Lines Matching +full:tx +full:- +full:ping +full:- +full:pong

1 // SPDX-License-Identifier: GPL-2.0+
8 * Copyright (C) 2010 - 2014 Xilinx, Inc.
10 * Some parts of this driver code is based on the driver for at91-series
17 #include <linux/dma-mapping.h>
109 * struct xusb_req - Xilinx USB device request structure
121 * struct xusb_ep - USB end point structure.
159 * struct xusb_udc - USB peripheral driver structure
168 * @setupseqtx: tx status
201 static const char driver_name[] = "xilinx-udc";
214 * xudc_write32 - little endian write to device registers
225 * xudc_read32 - little endian read from device registers
235 * xudc_write32_be - big endian write to device registers
246 * xudc_read32_be - big endian read from device registers
256 * xudc_wrstatus - Sets up the usb device status stages.
261 struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; in xudc_wrstatus()
264 epcfgreg = udc->read_fn(udc->addr + ep0->offset)| in xudc_wrstatus()
266 udc->write_fn(udc->addr, ep0->offset, epcfgreg); in xudc_wrstatus()
267 udc->write_fn(udc->addr, ep0->offset + XUSB_EP_BUF0COUNT_OFFSET, 0); in xudc_wrstatus()
268 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in xudc_wrstatus()
272 * xudc_epconfig - Configures the given endpoint.
287 epcfgreg = ((ep->is_in << 29) | (ep->is_iso << 28) | in xudc_epconfig()
288 (ep->ep_usb.maxpacket << 15) | (ep->rambase)); in xudc_epconfig()
289 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_epconfig()
292 udc->write_fn(udc->addr, ep->offset + XUSB_EP_BUF0COUNT_OFFSET, in xudc_epconfig()
293 ep->buffer0count); in xudc_epconfig()
294 udc->write_fn(udc->addr, ep->offset + XUSB_EP_BUF1COUNT_OFFSET, in xudc_epconfig()
295 ep->buffer1count); in xudc_epconfig()
296 if (ep->buffer0ready) in xudc_epconfig()
297 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in xudc_epconfig()
298 1 << ep->epnumber); in xudc_epconfig()
299 if (ep->buffer1ready) in xudc_epconfig()
300 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in xudc_epconfig()
301 1 << (ep->epnumber + XUSB_STATUS_EP_BUFF2_SHIFT)); in xudc_epconfig()
305 * xudc_start_dma - Starts DMA transfer.
319 struct xusb_udc *udc = ep->udc; in xudc_start_dma()
329 udc->write_fn(udc->addr, XUSB_DMA_DSAR_ADDR_OFFSET, src); in xudc_start_dma()
330 udc->write_fn(udc->addr, XUSB_DMA_DDAR_ADDR_OFFSET, dst); in xudc_start_dma()
331 udc->write_fn(udc->addr, XUSB_DMA_LENGTH_OFFSET, length); in xudc_start_dma()
339 reg = udc->read_fn(udc->addr + XUSB_DMA_STATUS_OFFSET); in xudc_start_dma()
347 timeout--; in xudc_start_dma()
349 dev_err(udc->dev, "DMA timeout\n"); in xudc_start_dma()
350 return -ETIMEDOUT; in xudc_start_dma()
355 if ((udc->read_fn(udc->addr + XUSB_DMA_STATUS_OFFSET) & in xudc_start_dma()
357 dev_err(udc->dev, "DMA Error\n"); in xudc_start_dma()
358 rc = -EINVAL; in xudc_start_dma()
365 * xudc_dma_send - Sends IN data using DMA.
371 * Return: 0 on success, -EAGAIN if no buffer is free and error
382 struct xusb_udc *udc = ep->udc; in xudc_dma_send()
384 src = req->usb_req.dma + req->usb_req.actual; in xudc_dma_send()
385 if (req->usb_req.length) in xudc_dma_send()
386 dma_sync_single_for_device(udc->dev, src, in xudc_dma_send()
388 if (!ep->curbufnum && !ep->buffer0ready) { in xudc_dma_send()
390 eprambase = (u32 __force *)(udc->addr + ep->rambase); in xudc_dma_send()
392 udc->write_fn(udc->addr, ep->offset + in xudc_dma_send()
394 udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, in xudc_dma_send()
395 XUSB_DMA_BRR_CTRL | (1 << ep->epnumber)); in xudc_dma_send()
396 ep->buffer0ready = 1; in xudc_dma_send()
397 ep->curbufnum = 1; in xudc_dma_send()
398 } else if (ep->curbufnum && !ep->buffer1ready) { in xudc_dma_send()
400 eprambase = (u32 __force *)(udc->addr + ep->rambase + in xudc_dma_send()
401 ep->ep_usb.maxpacket); in xudc_dma_send()
403 udc->write_fn(udc->addr, ep->offset + in xudc_dma_send()
405 udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, in xudc_dma_send()
406 XUSB_DMA_BRR_CTRL | (1 << (ep->epnumber + in xudc_dma_send()
408 ep->buffer1ready = 1; in xudc_dma_send()
409 ep->curbufnum = 0; in xudc_dma_send()
411 /* None of ping pong buffers are ready currently .*/ in xudc_dma_send()
412 return -EAGAIN; in xudc_dma_send()
419 * xudc_dma_receive - Receives OUT data using DMA.
425 * Return: 0 on success, -EAGAIN if no buffer is free and error
436 struct xusb_udc *udc = ep->udc; in xudc_dma_receive()
438 dst = req->usb_req.dma + req->usb_req.actual; in xudc_dma_receive()
439 if (!ep->curbufnum && !ep->buffer0ready) { in xudc_dma_receive()
441 eprambase = (u32 __force *)(udc->addr + ep->rambase); in xudc_dma_receive()
443 udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, in xudc_dma_receive()
445 (1 << ep->epnumber)); in xudc_dma_receive()
446 ep->buffer0ready = 1; in xudc_dma_receive()
447 ep->curbufnum = 1; in xudc_dma_receive()
448 } else if (ep->curbufnum && !ep->buffer1ready) { in xudc_dma_receive()
450 eprambase = (u32 __force *)(udc->addr + in xudc_dma_receive()
451 ep->rambase + ep->ep_usb.maxpacket); in xudc_dma_receive()
453 udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, in xudc_dma_receive()
455 (1 << (ep->epnumber + in xudc_dma_receive()
457 ep->buffer1ready = 1; in xudc_dma_receive()
458 ep->curbufnum = 0; in xudc_dma_receive()
460 /* None of the ping-pong buffers are ready currently */ in xudc_dma_receive()
461 return -EAGAIN; in xudc_dma_receive()
468 * xudc_eptxrx - Transmits or receives data to or from an endpoint.
474 * Return: 0 on success, -EAGAIN if no buffer is free.
485 struct xusb_udc *udc = ep->udc; in xudc_eptxrx()
488 if (udc->dma_enabled) { in xudc_eptxrx()
489 if (ep->is_in) in xudc_eptxrx()
495 /* Put the transmit buffer into the correct ping-pong buffer.*/ in xudc_eptxrx()
496 if (!ep->curbufnum && !ep->buffer0ready) { in xudc_eptxrx()
498 eprambase = (u32 __force *)(udc->addr + ep->rambase); in xudc_eptxrx()
499 if (ep->is_in) { in xudc_eptxrx()
502 udc->write_fn(udc->addr, ep->offset + in xudc_eptxrx()
511 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in xudc_eptxrx()
512 1 << ep->epnumber); in xudc_eptxrx()
513 ep->buffer0ready = 1; in xudc_eptxrx()
514 ep->curbufnum = 1; in xudc_eptxrx()
515 } else if (ep->curbufnum && !ep->buffer1ready) { in xudc_eptxrx()
517 eprambase = (u32 __force *)(udc->addr + ep->rambase + in xudc_eptxrx()
518 ep->ep_usb.maxpacket); in xudc_eptxrx()
519 if (ep->is_in) { in xudc_eptxrx()
522 udc->write_fn(udc->addr, ep->offset + in xudc_eptxrx()
531 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in xudc_eptxrx()
532 1 << (ep->epnumber + XUSB_STATUS_EP_BUFF2_SHIFT)); in xudc_eptxrx()
533 ep->buffer1ready = 1; in xudc_eptxrx()
534 ep->curbufnum = 0; in xudc_eptxrx()
536 /* None of the ping-pong buffers are ready currently */ in xudc_eptxrx()
537 return -EAGAIN; in xudc_eptxrx()
543 * xudc_done - Exeutes the endpoint data transfer completion tasks.
553 struct xusb_udc *udc = ep->udc; in xudc_done()
555 list_del_init(&req->queue); in xudc_done()
557 if (req->usb_req.status == -EINPROGRESS) in xudc_done()
558 req->usb_req.status = status; in xudc_done()
560 status = req->usb_req.status; in xudc_done()
562 if (status && status != -ESHUTDOWN) in xudc_done()
563 dev_dbg(udc->dev, "%s done %p, status %d\n", in xudc_done()
564 ep->ep_usb.name, req, status); in xudc_done()
566 if (udc->dma_enabled && ep->epnumber && req->usb_req.length) in xudc_done()
567 usb_gadget_unmap_request(&udc->gadget, &req->usb_req, in xudc_done()
568 ep->is_in); in xudc_done()
570 if (req->usb_req.complete) { in xudc_done()
571 spin_unlock(&udc->lock); in xudc_done()
572 req->usb_req.complete(&ep->ep_usb, &req->usb_req); in xudc_done()
573 spin_lock(&udc->lock); in xudc_done()
578 * xudc_read_fifo - Reads the data from the given endpoint buffer.
582 * Return: 0 if request is completed and -EAGAIN if not completed.
593 int retval = -EAGAIN; in xudc_read_fifo()
594 struct xusb_udc *udc = ep->udc; in xudc_read_fifo()
596 if (ep->buffer0ready && ep->buffer1ready) { in xudc_read_fifo()
597 dev_dbg(udc->dev, "Packet NOT ready!\n"); in xudc_read_fifo()
601 if (ep->curbufnum) in xudc_read_fifo()
606 count = udc->read_fn(udc->addr + ep->offset + bufoffset); in xudc_read_fifo()
608 if (!ep->buffer0ready && !ep->buffer1ready) in xudc_read_fifo()
611 buf = req->usb_req.buf + req->usb_req.actual; in xudc_read_fifo()
613 bufferspace = req->usb_req.length - req->usb_req.actual; in xudc_read_fifo()
614 is_short = count < ep->ep_usb.maxpacket; in xudc_read_fifo()
622 if (req->usb_req.status != -EOVERFLOW) in xudc_read_fifo()
623 dev_dbg(udc->dev, "%s overflow %d\n", in xudc_read_fifo()
624 ep->ep_usb.name, count); in xudc_read_fifo()
625 req->usb_req.status = -EOVERFLOW; in xudc_read_fifo()
626 xudc_done(ep, req, -EOVERFLOW); in xudc_read_fifo()
633 req->usb_req.actual += min(count, bufferspace); in xudc_read_fifo()
634 dev_dbg(udc->dev, "read %s, %d bytes%s req %p %d/%d\n", in xudc_read_fifo()
635 ep->ep_usb.name, count, is_short ? "/S" : "", req, in xudc_read_fifo()
636 req->usb_req.actual, req->usb_req.length); in xudc_read_fifo()
639 if ((req->usb_req.actual == req->usb_req.length) || is_short) { in xudc_read_fifo()
640 if (udc->dma_enabled && req->usb_req.length) in xudc_read_fifo()
641 dma_sync_single_for_cpu(udc->dev, in xudc_read_fifo()
642 req->usb_req.dma, in xudc_read_fifo()
643 req->usb_req.actual, in xudc_read_fifo()
653 case -EAGAIN: in xudc_read_fifo()
654 dev_dbg(udc->dev, "receive busy\n"); in xudc_read_fifo()
656 case -EINVAL: in xudc_read_fifo()
657 case -ETIMEDOUT: in xudc_read_fifo()
659 xudc_done(ep, req, -ECONNRESET); in xudc_read_fifo()
668 * xudc_write_fifo - Writes data into the given endpoint buffer.
672 * Return: 0 if request is completed and -EAGAIN if not completed.
681 int retval = -EAGAIN; in xudc_write_fifo()
682 struct xusb_udc *udc = ep->udc; in xudc_write_fifo()
686 max = le16_to_cpu(ep->desc->wMaxPacketSize); in xudc_write_fifo()
687 buf = req->usb_req.buf + req->usb_req.actual; in xudc_write_fifo()
689 length = req->usb_req.length - req->usb_req.actual; in xudc_write_fifo()
695 req->usb_req.actual += length; in xudc_write_fifo()
699 if (likely(req->usb_req.length != in xudc_write_fifo()
700 req->usb_req.actual) || req->usb_req.zero) in xudc_write_fifo()
705 dev_dbg(udc->dev, "%s: wrote %s %d bytes%s%s %d left %p\n", in xudc_write_fifo()
706 __func__, ep->ep_usb.name, length, is_last ? "/L" : "", in xudc_write_fifo()
708 req->usb_req.length - req->usb_req.actual, req); in xudc_write_fifo()
715 case -EAGAIN: in xudc_write_fifo()
716 dev_dbg(udc->dev, "Send busy\n"); in xudc_write_fifo()
718 case -EINVAL: in xudc_write_fifo()
719 case -ETIMEDOUT: in xudc_write_fifo()
721 xudc_done(ep, req, -ECONNRESET); in xudc_write_fifo()
730 * xudc_nuke - Cleans up the data transfer message list.
738 while (!list_empty(&ep->queue)) { in xudc_nuke()
739 req = list_first_entry(&ep->queue, struct xusb_req, queue); in xudc_nuke()
745 * xudc_ep_set_halt - Stalls/unstalls the given endpoint.
758 if (!_ep || (!ep->desc && ep->epnumber)) { in xudc_ep_set_halt()
760 return -EINVAL; in xudc_ep_set_halt()
762 udc = ep->udc; in xudc_ep_set_halt()
764 if (ep->is_in && (!list_empty(&ep->queue)) && value) { in xudc_ep_set_halt()
765 dev_dbg(udc->dev, "requests pending can't halt\n"); in xudc_ep_set_halt()
766 return -EAGAIN; in xudc_ep_set_halt()
769 if (ep->buffer0ready || ep->buffer1ready) { in xudc_ep_set_halt()
770 dev_dbg(udc->dev, "HW buffers busy can't halt\n"); in xudc_ep_set_halt()
771 return -EAGAIN; in xudc_ep_set_halt()
774 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_set_halt()
778 epcfgreg = udc->read_fn(udc->addr + ep->offset); in xudc_ep_set_halt()
780 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_ep_set_halt()
783 epcfgreg = udc->read_fn(udc->addr + ep->offset); in xudc_ep_set_halt()
785 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_ep_set_halt()
786 if (ep->epnumber) { in xudc_ep_set_halt()
788 epcfgreg = udc->read_fn(ep->udc->addr + ep->offset); in xudc_ep_set_halt()
790 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_ep_set_halt()
794 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_set_halt()
799 * __xudc_ep_enable - Enables the given endpoint.
808 struct xusb_udc *udc = ep->udc; in __xudc_ep_enable()
814 ep->is_in = ((desc->bEndpointAddress & USB_DIR_IN) != 0); in __xudc_ep_enable()
816 ep->epnumber = (desc->bEndpointAddress & 0x0f); in __xudc_ep_enable()
817 ep->desc = desc; in __xudc_ep_enable()
818 ep->ep_usb.desc = desc; in __xudc_ep_enable()
819 tmp = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; in __xudc_ep_enable()
820 ep->ep_usb.maxpacket = maxpacket = le16_to_cpu(desc->wMaxPacketSize); in __xudc_ep_enable()
824 dev_dbg(udc->dev, "only one control endpoint\n"); in __xudc_ep_enable()
825 /* NON- ISO */ in __xudc_ep_enable()
826 ep->is_iso = 0; in __xudc_ep_enable()
827 return -EINVAL; in __xudc_ep_enable()
829 /* NON- ISO */ in __xudc_ep_enable()
830 ep->is_iso = 0; in __xudc_ep_enable()
832 dev_dbg(udc->dev, "bogus maxpacket %d\n", maxpacket); in __xudc_ep_enable()
833 return -EINVAL; in __xudc_ep_enable()
837 /* NON- ISO */ in __xudc_ep_enable()
838 ep->is_iso = 0; in __xudc_ep_enable()
841 dev_dbg(udc->dev, "bogus maxpacket %d\n", maxpacket); in __xudc_ep_enable()
842 return -EINVAL; in __xudc_ep_enable()
847 ep->is_iso = 1; in __xudc_ep_enable()
851 ep->buffer0ready = false; in __xudc_ep_enable()
852 ep->buffer1ready = false; in __xudc_ep_enable()
853 ep->curbufnum = 0; in __xudc_ep_enable()
854 ep->rambase = rambase[ep->epnumber]; in __xudc_ep_enable()
857 dev_dbg(udc->dev, "Enable Endpoint %d max pkt is %d\n", in __xudc_ep_enable()
858 ep->epnumber, maxpacket); in __xudc_ep_enable()
861 epcfg = udc->read_fn(udc->addr + ep->offset); in __xudc_ep_enable()
863 udc->write_fn(udc->addr, ep->offset, epcfg); in __xudc_ep_enable()
864 if (ep->epnumber) in __xudc_ep_enable()
865 ep->rambase <<= 2; in __xudc_ep_enable()
868 ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in __xudc_ep_enable()
869 ier |= (XUSB_STATUS_INTR_BUFF_COMP_SHIFT_MASK << ep->epnumber); in __xudc_ep_enable()
870 udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); in __xudc_ep_enable()
873 if (ep->epnumber && !ep->is_in) { in __xudc_ep_enable()
874 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in __xudc_ep_enable()
875 1 << ep->epnumber); in __xudc_ep_enable()
876 ep->buffer0ready = true; in __xudc_ep_enable()
877 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in __xudc_ep_enable()
878 (1 << (ep->epnumber + in __xudc_ep_enable()
880 ep->buffer1ready = true; in __xudc_ep_enable()
887 * xudc_ep_enable - Enables the given endpoint.
901 if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { in xudc_ep_enable()
903 return -EINVAL; in xudc_ep_enable()
907 udc = ep->udc; in xudc_ep_enable()
909 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in xudc_ep_enable()
910 dev_dbg(udc->dev, "bogus device state\n"); in xudc_ep_enable()
911 return -ESHUTDOWN; in xudc_ep_enable()
914 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_enable()
916 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_enable()
922 * xudc_ep_disable - Disables the given endpoint.
936 return -EINVAL; in xudc_ep_disable()
940 udc = ep->udc; in xudc_ep_disable()
942 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_disable()
944 xudc_nuke(ep, -ESHUTDOWN); in xudc_ep_disable()
947 ep->desc = NULL; in xudc_ep_disable()
948 ep->ep_usb.desc = NULL; in xudc_ep_disable()
950 dev_dbg(udc->dev, "USB Ep %d disable\n", ep->epnumber); in xudc_ep_disable()
952 epcfg = udc->read_fn(udc->addr + ep->offset); in xudc_ep_disable()
954 udc->write_fn(udc->addr, ep->offset, epcfg); in xudc_ep_disable()
956 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_disable()
961 * xudc_ep_alloc_request - Initializes the request queue.
977 req->ep = ep; in xudc_ep_alloc_request()
978 INIT_LIST_HEAD(&req->queue); in xudc_ep_alloc_request()
979 return &req->usb_req; in xudc_ep_alloc_request()
983 * xudc_free_request - Releases the request from queue.
995 * __xudc_ep0_queue - Adds the request to endpoint 0 queue.
1003 struct xusb_udc *udc = ep0->udc; in __xudc_ep0_queue()
1007 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in __xudc_ep0_queue()
1008 dev_dbg(udc->dev, "%s, bogus device state\n", __func__); in __xudc_ep0_queue()
1009 return -EINVAL; in __xudc_ep0_queue()
1011 if (!list_empty(&ep0->queue)) { in __xudc_ep0_queue()
1012 dev_dbg(udc->dev, "%s:ep0 busy\n", __func__); in __xudc_ep0_queue()
1013 return -EBUSY; in __xudc_ep0_queue()
1016 req->usb_req.status = -EINPROGRESS; in __xudc_ep0_queue()
1017 req->usb_req.actual = 0; in __xudc_ep0_queue()
1019 list_add_tail(&req->queue, &ep0->queue); in __xudc_ep0_queue()
1021 if (udc->setup.bRequestType & USB_DIR_IN) { in __xudc_ep0_queue()
1022 prefetch(req->usb_req.buf); in __xudc_ep0_queue()
1023 length = req->usb_req.length; in __xudc_ep0_queue()
1024 corebuf = (void __force *) ((ep0->rambase << 2) + in __xudc_ep0_queue()
1025 udc->addr); in __xudc_ep0_queue()
1026 length = req->usb_req.actual = min_t(u32, length, in __xudc_ep0_queue()
1028 memcpy_toio((void __iomem *)corebuf, req->usb_req.buf, length); in __xudc_ep0_queue()
1029 udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, length); in __xudc_ep0_queue()
1030 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in __xudc_ep0_queue()
1032 if (udc->setup.wLength) { in __xudc_ep0_queue()
1034 udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, 0); in __xudc_ep0_queue()
1035 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in __xudc_ep0_queue()
1045 * xudc_ep0_queue - Adds the request to endpoint 0 queue.
1057 struct xusb_udc *udc = ep0->udc; in xudc_ep0_queue()
1061 spin_lock_irqsave(&udc->lock, flags); in xudc_ep0_queue()
1063 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep0_queue()
1069 * xudc_ep_queue - Adds the request to endpoint queue.
1081 struct xusb_udc *udc = ep->udc; in xudc_ep_queue()
1085 if (!ep->desc) { in xudc_ep_queue()
1086 dev_dbg(udc->dev, "%s: queuing request to disabled %s\n", in xudc_ep_queue()
1087 __func__, ep->name); in xudc_ep_queue()
1088 return -ESHUTDOWN; in xudc_ep_queue()
1091 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in xudc_ep_queue()
1092 dev_dbg(udc->dev, "%s, bogus device state\n", __func__); in xudc_ep_queue()
1093 return -EINVAL; in xudc_ep_queue()
1096 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_queue()
1098 _req->status = -EINPROGRESS; in xudc_ep_queue()
1099 _req->actual = 0; in xudc_ep_queue()
1101 if (udc->dma_enabled) { in xudc_ep_queue()
1102 ret = usb_gadget_map_request(&udc->gadget, &req->usb_req, in xudc_ep_queue()
1103 ep->is_in); in xudc_ep_queue()
1105 dev_dbg(udc->dev, "gadget_map failed ep%d\n", in xudc_ep_queue()
1106 ep->epnumber); in xudc_ep_queue()
1107 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_queue()
1108 return -EAGAIN; in xudc_ep_queue()
1112 if (list_empty(&ep->queue)) { in xudc_ep_queue()
1113 if (ep->is_in) { in xudc_ep_queue()
1114 dev_dbg(udc->dev, "xudc_write_fifo from ep_queue\n"); in xudc_ep_queue()
1118 dev_dbg(udc->dev, "xudc_read_fifo from ep_queue\n"); in xudc_ep_queue()
1125 list_add_tail(&req->queue, &ep->queue); in xudc_ep_queue()
1127 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_queue()
1132 * xudc_ep_dequeue - Removes the request from the queue.
1143 struct xusb_udc *udc = ep->udc; in xudc_ep_dequeue()
1146 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_dequeue()
1148 list_for_each_entry(iter, &ep->queue, queue) { in xudc_ep_dequeue()
1149 if (&iter->usb_req != _req) in xudc_ep_dequeue()
1155 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_dequeue()
1156 return -EINVAL; in xudc_ep_dequeue()
1158 xudc_done(ep, req, -ECONNRESET); in xudc_ep_dequeue()
1159 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_dequeue()
1165 * xudc_ep0_enable - Enables the given endpoint.
1176 return -EINVAL; in xudc_ep0_enable()
1180 * xudc_ep0_disable - Disables the given endpoint.
1189 return -EINVAL; in xudc_ep0_disable()
1213 * xudc_get_frame - Reads the current usb frame number.
1224 return -ENODEV; in xudc_get_frame()
1227 frame = udc->read_fn(udc->addr + XUSB_FRAMENUM_OFFSET); in xudc_get_frame()
1232 * xudc_wakeup - Send remote wakeup signal to host
1241 int status = -EINVAL; in xudc_wakeup()
1244 spin_lock_irqsave(&udc->lock, flags); in xudc_wakeup()
1247 if (!udc->remote_wkp) in xudc_wakeup()
1250 crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); in xudc_wakeup()
1253 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_wakeup()
1261 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_wakeup()
1264 spin_unlock_irqrestore(&udc->lock, flags); in xudc_wakeup()
1269 * xudc_pullup - start/stop USB traffic
1283 spin_lock_irqsave(&udc->lock, flags); in xudc_pullup()
1285 crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); in xudc_pullup()
1291 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_pullup()
1293 spin_unlock_irqrestore(&udc->lock, flags); in xudc_pullup()
1299 * xudc_eps_init - initialize endpoints.
1306 INIT_LIST_HEAD(&udc->gadget.ep_list); in xudc_eps_init()
1309 struct xusb_ep *ep = &udc->ep[ep_number]; in xudc_eps_init()
1312 list_add_tail(&ep->ep_usb.ep_list, in xudc_eps_init()
1313 &udc->gadget.ep_list); in xudc_eps_init()
1314 usb_ep_set_maxpacket_limit(&ep->ep_usb, in xudc_eps_init()
1316 snprintf(ep->name, EPNAME_SIZE, "ep%d", ep_number); in xudc_eps_init()
1317 ep->ep_usb.name = ep->name; in xudc_eps_init()
1318 ep->ep_usb.ops = &xusb_ep_ops; in xudc_eps_init()
1320 ep->ep_usb.caps.type_iso = true; in xudc_eps_init()
1321 ep->ep_usb.caps.type_bulk = true; in xudc_eps_init()
1322 ep->ep_usb.caps.type_int = true; in xudc_eps_init()
1324 ep->ep_usb.name = ep0name; in xudc_eps_init()
1325 usb_ep_set_maxpacket_limit(&ep->ep_usb, EP0_MAX_PACKET); in xudc_eps_init()
1326 ep->ep_usb.ops = &xusb_ep0_ops; in xudc_eps_init()
1328 ep->ep_usb.caps.type_control = true; in xudc_eps_init()
1331 ep->ep_usb.caps.dir_in = true; in xudc_eps_init()
1332 ep->ep_usb.caps.dir_out = true; in xudc_eps_init()
1334 ep->udc = udc; in xudc_eps_init()
1335 ep->epnumber = ep_number; in xudc_eps_init()
1336 ep->desc = NULL; in xudc_eps_init()
1341 ep->offset = XUSB_EP0_CONFIG_OFFSET + (ep_number * 0x10); in xudc_eps_init()
1342 ep->is_in = 0; in xudc_eps_init()
1343 ep->is_iso = 0; in xudc_eps_init()
1344 ep->maxpacket = 0; in xudc_eps_init()
1348 INIT_LIST_HEAD(&ep->queue); in xudc_eps_init()
1353 * xudc_stop_activity - Stops any further activity on the device.
1362 ep = &udc->ep[i]; in xudc_stop_activity()
1363 xudc_nuke(ep, -ESHUTDOWN); in xudc_stop_activity()
1368 * xudc_start - Starts the device.
1378 struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; in xudc_start()
1383 spin_lock_irqsave(&udc->lock, flags); in xudc_start()
1385 if (udc->driver) { in xudc_start()
1386 dev_err(udc->dev, "%s is already bound to %s\n", in xudc_start()
1387 udc->gadget.name, udc->driver->driver.name); in xudc_start()
1388 ret = -EBUSY; in xudc_start()
1393 udc->driver = driver; in xudc_start()
1394 udc->gadget.speed = driver->max_speed; in xudc_start()
1400 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); in xudc_start()
1401 udc->remote_wkp = 0; in xudc_start()
1403 spin_unlock_irqrestore(&udc->lock, flags); in xudc_start()
1408 * xudc_stop - stops the device.
1418 spin_lock_irqsave(&udc->lock, flags); in xudc_stop()
1420 udc->gadget.speed = USB_SPEED_UNKNOWN; in xudc_stop()
1421 udc->driver = NULL; in xudc_stop()
1424 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); in xudc_stop()
1425 udc->remote_wkp = 0; in xudc_stop()
1429 spin_unlock_irqrestore(&udc->lock, flags); in xudc_stop()
1443 * xudc_clear_stall_all_ep - clears stall of every endpoint.
1453 ep = &udc->ep[i]; in xudc_clear_stall_all_ep()
1454 epcfgreg = udc->read_fn(udc->addr + ep->offset); in xudc_clear_stall_all_ep()
1456 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_clear_stall_all_ep()
1457 if (ep->epnumber) { in xudc_clear_stall_all_ep()
1459 epcfgreg = udc->read_fn(udc->addr + ep->offset); in xudc_clear_stall_all_ep()
1461 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_clear_stall_all_ep()
1467 * xudc_startup_handler - The usb device controller interrupt handler.
1479 dev_dbg(udc->dev, "Reset\n"); in xudc_startup_handler()
1482 udc->gadget.speed = USB_SPEED_HIGH; in xudc_startup_handler()
1484 udc->gadget.speed = USB_SPEED_FULL; in xudc_startup_handler()
1488 udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); in xudc_startup_handler()
1491 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); in xudc_startup_handler()
1492 udc->remote_wkp = 0; in xudc_startup_handler()
1495 intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_startup_handler()
1498 udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); in xudc_startup_handler()
1502 dev_dbg(udc->dev, "Suspend\n"); in xudc_startup_handler()
1505 intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_startup_handler()
1508 udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); in xudc_startup_handler()
1510 udc->usb_state = USB_STATE_SUSPENDED; in xudc_startup_handler()
1512 if (udc->driver->suspend) { in xudc_startup_handler()
1513 spin_unlock(&udc->lock); in xudc_startup_handler()
1514 udc->driver->suspend(&udc->gadget); in xudc_startup_handler()
1515 spin_lock(&udc->lock); in xudc_startup_handler()
1519 bool condition = (udc->usb_state != USB_STATE_SUSPENDED); in xudc_startup_handler()
1521 dev_WARN_ONCE(udc->dev, condition, in xudc_startup_handler()
1524 dev_dbg(udc->dev, "Resume\n"); in xudc_startup_handler()
1527 intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_startup_handler()
1530 udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); in xudc_startup_handler()
1532 udc->usb_state = 0; in xudc_startup_handler()
1534 if (udc->driver->resume) { in xudc_startup_handler()
1535 spin_unlock(&udc->lock); in xudc_startup_handler()
1536 udc->driver->resume(&udc->gadget); in xudc_startup_handler()
1537 spin_lock(&udc->lock); in xudc_startup_handler()
1542 dev_dbg(udc->dev, "Disconnect\n"); in xudc_startup_handler()
1545 intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_startup_handler()
1548 udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); in xudc_startup_handler()
1550 if (udc->driver && udc->driver->disconnect) { in xudc_startup_handler()
1551 spin_unlock(&udc->lock); in xudc_startup_handler()
1552 udc->driver->disconnect(&udc->gadget); in xudc_startup_handler()
1553 spin_lock(&udc->lock); in xudc_startup_handler()
1559 * xudc_ep0_stall - Stall endpoint zero.
1567 struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; in xudc_ep0_stall()
1569 epcfgreg = udc->read_fn(udc->addr + ep0->offset); in xudc_ep0_stall()
1571 udc->write_fn(udc->addr, ep0->offset, epcfgreg); in xudc_ep0_stall()
1575 * xudc_setaddress - executes SET_ADDRESS command
1582 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_setaddress()
1583 struct xusb_req *req = udc->req; in xudc_setaddress()
1586 req->usb_req.length = 0; in xudc_setaddress()
1591 dev_err(udc->dev, "Can't respond to SET ADDRESS request\n"); in xudc_setaddress()
1596 * xudc_getstatus - executes GET_STATUS command
1603 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_getstatus()
1604 struct xusb_req *req = udc->req; in xudc_getstatus()
1612 switch (udc->setup.bRequestType & USB_RECIP_MASK) { in xudc_getstatus()
1616 if (udc->remote_wkp) in xudc_getstatus()
1622 epnum = le16_to_cpu(udc->setup.wIndex) & USB_ENDPOINT_NUMBER_MASK; in xudc_getstatus()
1625 target_ep = &udc->ep[epnum]; in xudc_getstatus()
1626 epcfgreg = udc->read_fn(udc->addr + target_ep->offset); in xudc_getstatus()
1628 if (le16_to_cpu(udc->setup.wIndex) & USB_DIR_IN) { in xudc_getstatus()
1629 if (!target_ep->is_in) in xudc_getstatus()
1632 if (target_ep->is_in) in xudc_getstatus()
1642 req->usb_req.length = 2; in xudc_getstatus()
1643 *(__le16 *)req->usb_req.buf = cpu_to_le16(status); in xudc_getstatus()
1648 dev_err(udc->dev, "Can't respond to getstatus request\n"); in xudc_getstatus()
1653 * xudc_set_clear_feature - Executes the set feature and clear feature commands.
1660 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_set_clear_feature()
1661 struct xusb_req *req = udc->req; in xudc_set_clear_feature()
1666 int flag = (udc->setup.bRequest == USB_REQ_SET_FEATURE ? 1 : 0); in xudc_set_clear_feature()
1669 switch (udc->setup.bRequestType) { in xudc_set_clear_feature()
1671 switch (le16_to_cpu(udc->setup.wValue)) { in xudc_set_clear_feature()
1680 udc->remote_wkp = 1; in xudc_set_clear_feature()
1682 udc->remote_wkp = 0; in xudc_set_clear_feature()
1690 if (!udc->setup.wValue) { in xudc_set_clear_feature()
1691 endpoint = le16_to_cpu(udc->setup.wIndex) & in xudc_set_clear_feature()
1697 target_ep = &udc->ep[endpoint]; in xudc_set_clear_feature()
1698 outinbit = le16_to_cpu(udc->setup.wIndex) & in xudc_set_clear_feature()
1703 if (outinbit != target_ep->is_in) { in xudc_set_clear_feature()
1707 epcfgreg = udc->read_fn(udc->addr + target_ep->offset); in xudc_set_clear_feature()
1711 udc->write_fn(udc->addr, in xudc_set_clear_feature()
1712 target_ep->offset, epcfgreg); in xudc_set_clear_feature()
1716 udc->write_fn(udc->addr, in xudc_set_clear_feature()
1717 target_ep->offset, in xudc_set_clear_feature()
1723 udc->write_fn(udc->addr, in xudc_set_clear_feature()
1724 target_ep->offset, in xudc_set_clear_feature()
1735 req->usb_req.length = 0; in xudc_set_clear_feature()
1740 dev_err(udc->dev, "Can't respond to SET/CLEAR FEATURE\n"); in xudc_set_clear_feature()
1745 * xudc_handle_setup - Processes the setup packet.
1751 __must_hold(&udc->lock) in xudc_handle_setup()
1753 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_handle_setup()
1758 ep0rambase = (u32 __force *) (udc->addr + XUSB_SETUP_PKT_ADDR_OFFSET); in xudc_handle_setup()
1761 udc->setup = setup; in xudc_handle_setup()
1762 udc->setup.wValue = cpu_to_le16((u16 __force)setup.wValue); in xudc_handle_setup()
1763 udc->setup.wIndex = cpu_to_le16((u16 __force)setup.wIndex); in xudc_handle_setup()
1764 udc->setup.wLength = cpu_to_le16((u16 __force)setup.wLength); in xudc_handle_setup()
1767 xudc_nuke(ep0, -ECONNRESET); in xudc_handle_setup()
1769 if (udc->setup.bRequestType & USB_DIR_IN) { in xudc_handle_setup()
1771 udc->setupseqrx = STATUS_PHASE; in xudc_handle_setup()
1772 udc->setupseqtx = DATA_PHASE; in xudc_handle_setup()
1775 udc->setupseqrx = DATA_PHASE; in xudc_handle_setup()
1776 udc->setupseqtx = STATUS_PHASE; in xudc_handle_setup()
1779 switch (udc->setup.bRequest) { in xudc_handle_setup()
1782 if ((udc->setup.bRequestType & in xudc_handle_setup()
1790 if (udc->setup.bRequestType != (USB_DIR_OUT | in xudc_handle_setup()
1798 if ((udc->setup.bRequestType & USB_TYPE_MASK) in xudc_handle_setup()
1807 spin_unlock(&udc->lock); in xudc_handle_setup()
1808 if (udc->driver->setup(&udc->gadget, &setup) < 0) in xudc_handle_setup()
1810 spin_lock(&udc->lock); in xudc_handle_setup()
1814 * xudc_ep0_out - Processes the endpoint 0 OUT token.
1819 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_ep0_out()
1825 req = list_first_entry(&ep0->queue, struct xusb_req, queue); in xudc_ep0_out()
1827 switch (udc->setupseqrx) { in xudc_ep0_out()
1833 udc->setupseqrx = SETUP_PHASE; in xudc_ep0_out()
1834 udc->setupseqtx = SETUP_PHASE; in xudc_ep0_out()
1835 req->usb_req.actual = req->usb_req.length; in xudc_ep0_out()
1839 bytes_to_rx = udc->read_fn(udc->addr + in xudc_ep0_out()
1842 ep0rambase = (u8 __force *) (udc->addr + in xudc_ep0_out()
1843 (ep0->rambase << 2)); in xudc_ep0_out()
1844 buffer = req->usb_req.buf + req->usb_req.actual; in xudc_ep0_out()
1845 req->usb_req.actual = req->usb_req.actual + bytes_to_rx; in xudc_ep0_out()
1848 if (req->usb_req.length == req->usb_req.actual) { in xudc_ep0_out()
1853 udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, 0); in xudc_ep0_out()
1854 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in xudc_ep0_out()
1863 * xudc_ep0_in - Processes the endpoint 0 IN token.
1868 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_ep0_in()
1876 u8 test_mode = le16_to_cpu(udc->setup.wIndex) >> 8; in xudc_ep0_in()
1878 req = list_first_entry(&ep0->queue, struct xusb_req, queue); in xudc_ep0_in()
1879 bytes_to_tx = req->usb_req.length - req->usb_req.actual; in xudc_ep0_in()
1881 switch (udc->setupseqtx) { in xudc_ep0_in()
1883 switch (udc->setup.bRequest) { in xudc_ep0_in()
1886 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, in xudc_ep0_in()
1887 le16_to_cpu(udc->setup.wValue)); in xudc_ep0_in()
1890 if (udc->setup.bRequestType == in xudc_ep0_in()
1892 if (le16_to_cpu(udc->setup.wValue) == in xudc_ep0_in()
1894 udc->write_fn(udc->addr, in xudc_ep0_in()
1900 req->usb_req.actual = req->usb_req.length; in xudc_ep0_in()
1910 epcfgreg = udc->read_fn(udc->addr + ep0->offset); in xudc_ep0_in()
1912 udc->write_fn(udc->addr, ep0->offset, epcfgreg); in xudc_ep0_in()
1913 udc->setupseqtx = STATUS_PHASE; in xudc_ep0_in()
1918 ep0rambase = (u8 __force *) (udc->addr + in xudc_ep0_in()
1919 (ep0->rambase << 2)); in xudc_ep0_in()
1920 buffer = req->usb_req.buf + req->usb_req.actual; in xudc_ep0_in()
1921 req->usb_req.actual = req->usb_req.actual + length; in xudc_ep0_in()
1924 udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, count); in xudc_ep0_in()
1925 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in xudc_ep0_in()
1933 * xudc_ctrl_ep_handler - Endpoint 0 interrupt handler.
1953 * xudc_nonctrl_ep_handler - Non control endpoint interrupt handler.
1968 ep = &udc->ep[epnum]; in xudc_nonctrl_ep_handler()
1971 ep->buffer0ready = 0; in xudc_nonctrl_ep_handler()
1973 ep->buffer1ready = false; in xudc_nonctrl_ep_handler()
1975 if (list_empty(&ep->queue)) in xudc_nonctrl_ep_handler()
1978 req = list_first_entry(&ep->queue, struct xusb_req, queue); in xudc_nonctrl_ep_handler()
1980 if (ep->is_in) in xudc_nonctrl_ep_handler()
1987 * xudc_irq - The main interrupt handler.
2002 spin_lock_irqsave(&udc->lock, flags); in xudc_irq()
2008 ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_irq()
2010 udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); in xudc_irq()
2013 intrstatus = udc->read_fn(udc->addr + XUSB_STATUS_OFFSET); in xudc_irq()
2019 * - USB Reset received {XUSB_STATUS_RESET_MASK} in xudc_irq()
2020 * - USB Suspend received {XUSB_STATUS_SUSPEND_MASK} in xudc_irq()
2021 * - USB Resume received {XUSB_STATUS_RESUME_MASK} in xudc_irq()
2022 * - USB Disconnect received {XUSB_STATUS_DISCONNECT_MASK} in xudc_irq()
2030 ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_irq()
2032 udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); in xudc_irq()
2040 (index - 1))) || (intrstatus & in xudc_irq()
2042 (index - 1)))); in xudc_irq()
2050 spin_unlock_irqrestore(&udc->lock, flags); in xudc_irq()
2055 * xudc_probe - The device probe function for driver initialization.
2062 struct device_node *np = pdev->dev.of_node; in xudc_probe()
2070 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); in xudc_probe()
2072 return -ENOMEM; in xudc_probe()
2075 udc->req = devm_kzalloc(&pdev->dev, sizeof(struct xusb_req), in xudc_probe()
2077 if (!udc->req) in xudc_probe()
2078 return -ENOMEM; in xudc_probe()
2080 buff = devm_kzalloc(&pdev->dev, STATUSBUFF_SIZE, GFP_KERNEL); in xudc_probe()
2082 return -ENOMEM; in xudc_probe()
2084 udc->req->usb_req.buf = buff; in xudc_probe()
2087 udc->addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in xudc_probe()
2088 if (IS_ERR(udc->addr)) in xudc_probe()
2089 return PTR_ERR(udc->addr); in xudc_probe()
2094 ret = devm_request_irq(&pdev->dev, irq, xudc_irq, 0, in xudc_probe()
2095 dev_name(&pdev->dev), udc); in xudc_probe()
2097 dev_dbg(&pdev->dev, "unable to request irq %d", irq); in xudc_probe()
2101 udc->dma_enabled = of_property_read_bool(np, "xlnx,has-builtin-dma"); in xudc_probe()
2104 udc->gadget.ops = &xusb_udc_ops; in xudc_probe()
2105 udc->gadget.max_speed = USB_SPEED_HIGH; in xudc_probe()
2106 udc->gadget.speed = USB_SPEED_UNKNOWN; in xudc_probe()
2107 udc->gadget.ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO].ep_usb; in xudc_probe()
2108 udc->gadget.name = driver_name; in xudc_probe()
2110 udc->clk = devm_clk_get(&pdev->dev, "s_axi_aclk"); in xudc_probe()
2111 if (IS_ERR(udc->clk)) { in xudc_probe()
2112 if (PTR_ERR(udc->clk) != -ENOENT) { in xudc_probe()
2113 ret = PTR_ERR(udc->clk); in xudc_probe()
2121 dev_warn(&pdev->dev, "s_axi_aclk clock property is not found\n"); in xudc_probe()
2122 udc->clk = NULL; in xudc_probe()
2125 ret = clk_prepare_enable(udc->clk); in xudc_probe()
2127 dev_err(&pdev->dev, "Unable to enable clock.\n"); in xudc_probe()
2131 spin_lock_init(&udc->lock); in xudc_probe()
2134 udc->write_fn = xudc_write32_be; in xudc_probe()
2135 udc->read_fn = xudc_read32_be; in xudc_probe()
2136 udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, USB_TEST_J); in xudc_probe()
2137 if ((udc->read_fn(udc->addr + XUSB_TESTMODE_OFFSET)) in xudc_probe()
2139 udc->write_fn = xudc_write32; in xudc_probe()
2140 udc->read_fn = xudc_read32; in xudc_probe()
2142 udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); in xudc_probe()
2147 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); in xudc_probe()
2149 ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); in xudc_probe()
2153 udc->dev = &udc->gadget.dev; in xudc_probe()
2161 udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); in xudc_probe()
2165 dev_vdbg(&pdev->dev, "%s at 0x%08X mapped to %p %s\n", in xudc_probe()
2166 driver_name, (u32)res->start, udc->addr, in xudc_probe()
2167 udc->dma_enabled ? "with DMA" : "without DMA"); in xudc_probe()
2172 clk_disable_unprepare(udc->clk); in xudc_probe()
2174 dev_err(&pdev->dev, "probe failed, %d\n", ret); in xudc_probe()
2179 * xudc_remove - Releases the resources allocated during the initialization.
2188 usb_del_gadget_udc(&udc->gadget); in xudc_remove()
2189 clk_disable_unprepare(udc->clk); in xudc_remove()
2201 spin_lock_irqsave(&udc->lock, flags); in xudc_suspend()
2203 crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); in xudc_suspend()
2206 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_suspend()
2208 spin_unlock_irqrestore(&udc->lock, flags); in xudc_suspend()
2209 if (udc->driver && udc->driver->suspend) in xudc_suspend()
2210 udc->driver->suspend(&udc->gadget); in xudc_suspend()
2212 clk_disable(udc->clk); in xudc_suspend()
2226 ret = clk_enable(udc->clk); in xudc_resume()
2230 spin_lock_irqsave(&udc->lock, flags); in xudc_resume()
2232 crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); in xudc_resume()
2235 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_resume()
2237 spin_unlock_irqrestore(&udc->lock, flags); in xudc_resume()
2249 { .compatible = "xlnx,usb2-device-4.00.a", },