Lines Matching refs:udc
144 struct xusb_udc *udc; member
261 static void xudc_wrstatus(struct xusb_udc *udc) in xudc_wrstatus() argument
263 struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; in xudc_wrstatus()
266 epcfgreg = udc->read_fn(udc->addr + ep0->offset)| in xudc_wrstatus()
268 udc->write_fn(udc->addr, ep0->offset, epcfgreg); in xudc_wrstatus()
269 udc->write_fn(udc->addr, ep0->offset + XUSB_EP_BUF0COUNT_OFFSET, 0); in xudc_wrstatus()
270 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in xudc_wrstatus()
281 static void xudc_epconfig(struct xusb_ep *ep, struct xusb_udc *udc) in xudc_epconfig() argument
291 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_epconfig()
294 udc->write_fn(udc->addr, ep->offset + XUSB_EP_BUF0COUNT_OFFSET, in xudc_epconfig()
296 udc->write_fn(udc->addr, ep->offset + XUSB_EP_BUF1COUNT_OFFSET, in xudc_epconfig()
299 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in xudc_epconfig()
302 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in xudc_epconfig()
321 struct xusb_udc *udc = ep->udc; in xudc_start_dma() local
331 udc->write_fn(udc->addr, XUSB_DMA_DSAR_ADDR_OFFSET, src); in xudc_start_dma()
332 udc->write_fn(udc->addr, XUSB_DMA_DDAR_ADDR_OFFSET, dst); in xudc_start_dma()
333 udc->write_fn(udc->addr, XUSB_DMA_LENGTH_OFFSET, length); in xudc_start_dma()
341 reg = udc->read_fn(udc->addr + XUSB_DMA_STATUS_OFFSET); in xudc_start_dma()
351 dev_err(udc->dev, "DMA timeout\n"); in xudc_start_dma()
357 if ((udc->read_fn(udc->addr + XUSB_DMA_STATUS_OFFSET) & in xudc_start_dma()
359 dev_err(udc->dev, "DMA Error\n"); in xudc_start_dma()
384 struct xusb_udc *udc = ep->udc; in xudc_dma_send() local
388 dma_sync_single_for_device(udc->dev, src, in xudc_dma_send()
392 eprambase = (u32 __force *)(udc->addr + ep->rambase); in xudc_dma_send()
394 udc->write_fn(udc->addr, ep->offset + in xudc_dma_send()
396 udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, in xudc_dma_send()
402 eprambase = (u32 __force *)(udc->addr + ep->rambase + in xudc_dma_send()
405 udc->write_fn(udc->addr, ep->offset + in xudc_dma_send()
407 udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, in xudc_dma_send()
438 struct xusb_udc *udc = ep->udc; in xudc_dma_receive() local
443 eprambase = (u32 __force *)(udc->addr + ep->rambase); in xudc_dma_receive()
445 udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, in xudc_dma_receive()
452 eprambase = (u32 __force *)(udc->addr + in xudc_dma_receive()
455 udc->write_fn(udc->addr, XUSB_DMA_CONTROL_OFFSET, in xudc_dma_receive()
487 struct xusb_udc *udc = ep->udc; in xudc_eptxrx() local
490 if (udc->dma_enabled) { in xudc_eptxrx()
500 eprambase = (u32 __force *)(udc->addr + ep->rambase); in xudc_eptxrx()
503 udc->write_fn(udc->addr, ep->offset + in xudc_eptxrx()
511 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in xudc_eptxrx()
517 eprambase = (u32 __force *)(udc->addr + ep->rambase + in xudc_eptxrx()
521 udc->write_fn(udc->addr, ep->offset + in xudc_eptxrx()
529 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in xudc_eptxrx()
551 struct xusb_udc *udc = ep->udc; in xudc_done() local
561 dev_dbg(udc->dev, "%s done %p, status %d\n", in xudc_done()
564 if (udc->dma_enabled && ep->epnumber && req->usb_req.length) in xudc_done()
565 usb_gadget_unmap_request(&udc->gadget, &req->usb_req, in xudc_done()
569 spin_unlock(&udc->lock); in xudc_done()
571 spin_lock(&udc->lock); in xudc_done()
592 struct xusb_udc *udc = ep->udc; in xudc_read_fifo() local
595 dev_dbg(udc->dev, "Packet NOT ready!\n"); in xudc_read_fifo()
604 count = udc->read_fn(udc->addr + ep->offset + bufoffset); in xudc_read_fifo()
621 dev_dbg(udc->dev, "%s overflow %d\n", in xudc_read_fifo()
632 dev_dbg(udc->dev, "read %s, %d bytes%s req %p %d/%d\n", in xudc_read_fifo()
638 if (udc->dma_enabled && req->usb_req.length) in xudc_read_fifo()
639 dma_sync_single_for_cpu(udc->dev, in xudc_read_fifo()
652 dev_dbg(udc->dev, "receive busy\n"); in xudc_read_fifo()
680 struct xusb_udc *udc = ep->udc; in xudc_write_fifo() local
703 dev_dbg(udc->dev, "%s: wrote %s %d bytes%s%s %d left %p\n", in xudc_write_fifo()
714 dev_dbg(udc->dev, "Send busy\n"); in xudc_write_fifo()
752 struct xusb_udc *udc; in xudc_ep_set_halt() local
760 udc = ep->udc; in xudc_ep_set_halt()
763 dev_dbg(udc->dev, "requests pending can't halt\n"); in xudc_ep_set_halt()
768 dev_dbg(udc->dev, "HW buffers busy can't halt\n"); in xudc_ep_set_halt()
772 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_set_halt()
776 epcfgreg = udc->read_fn(udc->addr + ep->offset); in xudc_ep_set_halt()
778 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_ep_set_halt()
781 epcfgreg = udc->read_fn(udc->addr + ep->offset); in xudc_ep_set_halt()
783 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_ep_set_halt()
786 epcfgreg = udc->read_fn(ep->udc->addr + ep->offset); in xudc_ep_set_halt()
788 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_ep_set_halt()
792 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_set_halt()
806 struct xusb_udc *udc = ep->udc; in __xudc_ep_enable() local
822 dev_dbg(udc->dev, "only one control endpoint\n"); in __xudc_ep_enable()
830 dev_dbg(udc->dev, "bogus maxpacket %d\n", maxpacket); in __xudc_ep_enable()
839 dev_dbg(udc->dev, "bogus maxpacket %d\n", maxpacket); in __xudc_ep_enable()
853 xudc_epconfig(ep, udc); in __xudc_ep_enable()
855 dev_dbg(udc->dev, "Enable Endpoint %d max pkt is %d\n", in __xudc_ep_enable()
859 epcfg = udc->read_fn(udc->addr + ep->offset); in __xudc_ep_enable()
861 udc->write_fn(udc->addr, ep->offset, epcfg); in __xudc_ep_enable()
866 ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in __xudc_ep_enable()
868 udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); in __xudc_ep_enable()
872 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in __xudc_ep_enable()
875 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, in __xudc_ep_enable()
895 struct xusb_udc *udc; in xudc_ep_enable() local
905 udc = ep->udc; in xudc_ep_enable()
907 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in xudc_ep_enable()
908 dev_dbg(udc->dev, "bogus device state\n"); in xudc_ep_enable()
912 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_enable()
914 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_enable()
930 struct xusb_udc *udc; in xudc_ep_disable() local
938 udc = ep->udc; in xudc_ep_disable()
940 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_disable()
948 dev_dbg(udc->dev, "USB Ep %d disable\n ", ep->epnumber); in xudc_ep_disable()
950 epcfg = udc->read_fn(udc->addr + ep->offset); in xudc_ep_disable()
952 udc->write_fn(udc->addr, ep->offset, epcfg); in xudc_ep_disable()
954 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_disable()
1001 struct xusb_udc *udc = ep0->udc; in __xudc_ep0_queue() local
1005 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in __xudc_ep0_queue()
1006 dev_dbg(udc->dev, "%s, bogus device state\n", __func__); in __xudc_ep0_queue()
1010 dev_dbg(udc->dev, "%s:ep0 busy\n", __func__); in __xudc_ep0_queue()
1019 if (udc->setup.bRequestType & USB_DIR_IN) { in __xudc_ep0_queue()
1023 udc->addr); in __xudc_ep0_queue()
1027 udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, length); in __xudc_ep0_queue()
1028 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in __xudc_ep0_queue()
1030 if (udc->setup.wLength) { in __xudc_ep0_queue()
1032 udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, 0); in __xudc_ep0_queue()
1033 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in __xudc_ep0_queue()
1035 xudc_wrstatus(udc); in __xudc_ep0_queue()
1055 struct xusb_udc *udc = ep0->udc; in xudc_ep0_queue() local
1059 spin_lock_irqsave(&udc->lock, flags); in xudc_ep0_queue()
1061 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep0_queue()
1079 struct xusb_udc *udc = ep->udc; in xudc_ep_queue() local
1084 dev_dbg(udc->dev, "%s: queuing request to disabled %s\n", in xudc_ep_queue()
1089 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in xudc_ep_queue()
1090 dev_dbg(udc->dev, "%s, bogus device state\n", __func__); in xudc_ep_queue()
1094 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_queue()
1099 if (udc->dma_enabled) { in xudc_ep_queue()
1100 ret = usb_gadget_map_request(&udc->gadget, &req->usb_req, in xudc_ep_queue()
1103 dev_dbg(udc->dev, "gadget_map failed ep%d\n", in xudc_ep_queue()
1105 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_queue()
1112 dev_dbg(udc->dev, "xudc_write_fifo from ep_queue\n"); in xudc_ep_queue()
1116 dev_dbg(udc->dev, "xudc_read_fifo from ep_queue\n"); in xudc_ep_queue()
1125 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_queue()
1141 struct xusb_udc *udc = ep->udc; in xudc_ep_dequeue() local
1144 spin_lock_irqsave(&udc->lock, flags); in xudc_ep_dequeue()
1153 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_dequeue()
1157 spin_unlock_irqrestore(&udc->lock, flags); in xudc_ep_dequeue()
1218 struct xusb_udc *udc; in xudc_get_frame() local
1224 udc = to_udc(gadget); in xudc_get_frame()
1225 frame = udc->read_fn(udc->addr + XUSB_FRAMENUM_OFFSET); in xudc_get_frame()
1237 struct xusb_udc *udc = to_udc(gadget); in xudc_wakeup() local
1242 spin_lock_irqsave(&udc->lock, flags); in xudc_wakeup()
1245 if (!udc->remote_wkp) in xudc_wakeup()
1248 crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); in xudc_wakeup()
1251 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_wakeup()
1259 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_wakeup()
1262 spin_unlock_irqrestore(&udc->lock, flags); in xudc_wakeup()
1277 struct xusb_udc *udc = to_udc(gadget); in xudc_pullup() local
1281 spin_lock_irqsave(&udc->lock, flags); in xudc_pullup()
1283 crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); in xudc_pullup()
1289 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_pullup()
1291 spin_unlock_irqrestore(&udc->lock, flags); in xudc_pullup()
1300 static void xudc_eps_init(struct xusb_udc *udc) in xudc_eps_init() argument
1304 INIT_LIST_HEAD(&udc->gadget.ep_list); in xudc_eps_init()
1307 struct xusb_ep *ep = &udc->ep[ep_number]; in xudc_eps_init()
1311 &udc->gadget.ep_list); in xudc_eps_init()
1332 ep->udc = udc; in xudc_eps_init()
1343 xudc_epconfig(ep, udc); in xudc_eps_init()
1354 static void xudc_stop_activity(struct xusb_udc *udc) in xudc_stop_activity() argument
1360 ep = &udc->ep[i]; in xudc_stop_activity()
1375 struct xusb_udc *udc = to_udc(gadget); in xudc_start() local
1376 struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; in xudc_start()
1381 spin_lock_irqsave(&udc->lock, flags); in xudc_start()
1383 if (udc->driver) { in xudc_start()
1384 dev_err(udc->dev, "%s is already bound to %s\n", in xudc_start()
1385 udc->gadget.name, udc->driver->driver.name); in xudc_start()
1391 udc->driver = driver; in xudc_start()
1392 udc->gadget.speed = driver->max_speed; in xudc_start()
1398 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); in xudc_start()
1399 udc->remote_wkp = 0; in xudc_start()
1401 spin_unlock_irqrestore(&udc->lock, flags); in xudc_start()
1413 struct xusb_udc *udc = to_udc(gadget); in xudc_stop() local
1416 spin_lock_irqsave(&udc->lock, flags); in xudc_stop()
1418 udc->gadget.speed = USB_SPEED_UNKNOWN; in xudc_stop()
1419 udc->driver = NULL; in xudc_stop()
1422 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); in xudc_stop()
1423 udc->remote_wkp = 0; in xudc_stop()
1425 xudc_stop_activity(udc); in xudc_stop()
1427 spin_unlock_irqrestore(&udc->lock, flags); in xudc_stop()
1444 static void xudc_clear_stall_all_ep(struct xusb_udc *udc) in xudc_clear_stall_all_ep() argument
1451 ep = &udc->ep[i]; in xudc_clear_stall_all_ep()
1452 epcfgreg = udc->read_fn(udc->addr + ep->offset); in xudc_clear_stall_all_ep()
1454 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_clear_stall_all_ep()
1457 epcfgreg = udc->read_fn(udc->addr + ep->offset); in xudc_clear_stall_all_ep()
1459 udc->write_fn(udc->addr, ep->offset, epcfgreg); in xudc_clear_stall_all_ep()
1471 static void xudc_startup_handler(struct xusb_udc *udc, u32 intrstatus) in xudc_startup_handler() argument
1477 dev_dbg(udc->dev, "Reset\n"); in xudc_startup_handler()
1480 udc->gadget.speed = USB_SPEED_HIGH; in xudc_startup_handler()
1482 udc->gadget.speed = USB_SPEED_FULL; in xudc_startup_handler()
1484 xudc_stop_activity(udc); in xudc_startup_handler()
1485 xudc_clear_stall_all_ep(udc); in xudc_startup_handler()
1486 udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); in xudc_startup_handler()
1489 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); in xudc_startup_handler()
1490 udc->remote_wkp = 0; in xudc_startup_handler()
1493 intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_startup_handler()
1496 udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); in xudc_startup_handler()
1500 dev_dbg(udc->dev, "Suspend\n"); in xudc_startup_handler()
1503 intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_startup_handler()
1506 udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); in xudc_startup_handler()
1508 udc->usb_state = USB_STATE_SUSPENDED; in xudc_startup_handler()
1510 if (udc->driver->suspend) { in xudc_startup_handler()
1511 spin_unlock(&udc->lock); in xudc_startup_handler()
1512 udc->driver->suspend(&udc->gadget); in xudc_startup_handler()
1513 spin_lock(&udc->lock); in xudc_startup_handler()
1517 bool condition = (udc->usb_state != USB_STATE_SUSPENDED); in xudc_startup_handler()
1519 dev_WARN_ONCE(udc->dev, condition, in xudc_startup_handler()
1522 dev_dbg(udc->dev, "Resume\n"); in xudc_startup_handler()
1525 intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_startup_handler()
1528 udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); in xudc_startup_handler()
1530 udc->usb_state = 0; in xudc_startup_handler()
1532 if (udc->driver->resume) { in xudc_startup_handler()
1533 spin_unlock(&udc->lock); in xudc_startup_handler()
1534 udc->driver->resume(&udc->gadget); in xudc_startup_handler()
1535 spin_lock(&udc->lock); in xudc_startup_handler()
1540 dev_dbg(udc->dev, "Disconnect\n"); in xudc_startup_handler()
1543 intrreg = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_startup_handler()
1546 udc->write_fn(udc->addr, XUSB_IER_OFFSET, intrreg); in xudc_startup_handler()
1548 if (udc->driver && udc->driver->disconnect) { in xudc_startup_handler()
1549 spin_unlock(&udc->lock); in xudc_startup_handler()
1550 udc->driver->disconnect(&udc->gadget); in xudc_startup_handler()
1551 spin_lock(&udc->lock); in xudc_startup_handler()
1562 static void xudc_ep0_stall(struct xusb_udc *udc) in xudc_ep0_stall() argument
1565 struct xusb_ep *ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO]; in xudc_ep0_stall()
1567 epcfgreg = udc->read_fn(udc->addr + ep0->offset); in xudc_ep0_stall()
1569 udc->write_fn(udc->addr, ep0->offset, epcfgreg); in xudc_ep0_stall()
1578 static void xudc_setaddress(struct xusb_udc *udc) in xudc_setaddress() argument
1580 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_setaddress()
1581 struct xusb_req *req = udc->req; in xudc_setaddress()
1589 dev_err(udc->dev, "Can't respond to SET ADDRESS request\n"); in xudc_setaddress()
1590 xudc_ep0_stall(udc); in xudc_setaddress()
1599 static void xudc_getstatus(struct xusb_udc *udc) in xudc_getstatus() argument
1601 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_getstatus()
1602 struct xusb_req *req = udc->req; in xudc_getstatus()
1610 switch (udc->setup.bRequestType & USB_RECIP_MASK) { in xudc_getstatus()
1614 if (udc->remote_wkp) in xudc_getstatus()
1620 epnum = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; in xudc_getstatus()
1623 target_ep = &udc->ep[epnum]; in xudc_getstatus()
1624 epcfgreg = udc->read_fn(udc->addr + target_ep->offset); in xudc_getstatus()
1626 if (udc->setup.wIndex & USB_DIR_IN) { in xudc_getstatus()
1646 dev_err(udc->dev, "Can't respond to getstatus request\n"); in xudc_getstatus()
1647 xudc_ep0_stall(udc); in xudc_getstatus()
1656 static void xudc_set_clear_feature(struct xusb_udc *udc) in xudc_set_clear_feature() argument
1658 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_set_clear_feature()
1659 struct xusb_req *req = udc->req; in xudc_set_clear_feature()
1664 int flag = (udc->setup.bRequest == USB_REQ_SET_FEATURE ? 1 : 0); in xudc_set_clear_feature()
1667 switch (udc->setup.bRequestType) { in xudc_set_clear_feature()
1669 switch (udc->setup.wValue) { in xudc_set_clear_feature()
1678 udc->remote_wkp = 1; in xudc_set_clear_feature()
1680 udc->remote_wkp = 0; in xudc_set_clear_feature()
1683 xudc_ep0_stall(udc); in xudc_set_clear_feature()
1688 if (!udc->setup.wValue) { in xudc_set_clear_feature()
1689 endpoint = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; in xudc_set_clear_feature()
1691 xudc_ep0_stall(udc); in xudc_set_clear_feature()
1694 target_ep = &udc->ep[endpoint]; in xudc_set_clear_feature()
1695 outinbit = udc->setup.wIndex & USB_ENDPOINT_DIR_MASK; in xudc_set_clear_feature()
1700 xudc_ep0_stall(udc); in xudc_set_clear_feature()
1703 epcfgreg = udc->read_fn(udc->addr + target_ep->offset); in xudc_set_clear_feature()
1707 udc->write_fn(udc->addr, in xudc_set_clear_feature()
1712 udc->write_fn(udc->addr, in xudc_set_clear_feature()
1719 udc->write_fn(udc->addr, in xudc_set_clear_feature()
1727 xudc_ep0_stall(udc); in xudc_set_clear_feature()
1736 dev_err(udc->dev, "Can't respond to SET/CLEAR FEATURE\n"); in xudc_set_clear_feature()
1737 xudc_ep0_stall(udc); in xudc_set_clear_feature()
1746 static void xudc_handle_setup(struct xusb_udc *udc) in xudc_handle_setup() argument
1747 __must_hold(&udc->lock) in xudc_handle_setup()
1749 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_handle_setup()
1754 ep0rambase = (u32 __force *) (udc->addr + XUSB_SETUP_PKT_ADDR_OFFSET); in xudc_handle_setup()
1757 udc->setup = setup; in xudc_handle_setup()
1758 udc->setup.wValue = cpu_to_le16(setup.wValue); in xudc_handle_setup()
1759 udc->setup.wIndex = cpu_to_le16(setup.wIndex); in xudc_handle_setup()
1760 udc->setup.wLength = cpu_to_le16(setup.wLength); in xudc_handle_setup()
1765 if (udc->setup.bRequestType & USB_DIR_IN) { in xudc_handle_setup()
1767 udc->setupseqrx = STATUS_PHASE; in xudc_handle_setup()
1768 udc->setupseqtx = DATA_PHASE; in xudc_handle_setup()
1771 udc->setupseqrx = DATA_PHASE; in xudc_handle_setup()
1772 udc->setupseqtx = STATUS_PHASE; in xudc_handle_setup()
1775 switch (udc->setup.bRequest) { in xudc_handle_setup()
1778 if ((udc->setup.bRequestType & in xudc_handle_setup()
1782 xudc_getstatus(udc); in xudc_handle_setup()
1786 if (udc->setup.bRequestType != (USB_DIR_OUT | in xudc_handle_setup()
1789 xudc_setaddress(udc); in xudc_handle_setup()
1794 if ((udc->setup.bRequestType & USB_TYPE_MASK) in xudc_handle_setup()
1797 xudc_set_clear_feature(udc); in xudc_handle_setup()
1803 spin_unlock(&udc->lock); in xudc_handle_setup()
1804 if (udc->driver->setup(&udc->gadget, &setup) < 0) in xudc_handle_setup()
1805 xudc_ep0_stall(udc); in xudc_handle_setup()
1806 spin_lock(&udc->lock); in xudc_handle_setup()
1813 static void xudc_ep0_out(struct xusb_udc *udc) in xudc_ep0_out() argument
1815 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_ep0_out()
1823 switch (udc->setupseqrx) { in xudc_ep0_out()
1829 udc->setupseqrx = SETUP_PHASE; in xudc_ep0_out()
1830 udc->setupseqtx = SETUP_PHASE; in xudc_ep0_out()
1835 bytes_to_rx = udc->read_fn(udc->addr + in xudc_ep0_out()
1838 ep0rambase = (u8 __force *) (udc->addr + in xudc_ep0_out()
1846 xudc_wrstatus(udc); in xudc_ep0_out()
1849 udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, 0); in xudc_ep0_out()
1850 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in xudc_ep0_out()
1862 static void xudc_ep0_in(struct xusb_udc *udc) in xudc_ep0_in() argument
1864 struct xusb_ep *ep0 = &udc->ep[0]; in xudc_ep0_in()
1872 u8 test_mode = udc->setup.wIndex >> 8; in xudc_ep0_in()
1877 switch (udc->setupseqtx) { in xudc_ep0_in()
1879 switch (udc->setup.bRequest) { in xudc_ep0_in()
1882 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, in xudc_ep0_in()
1883 udc->setup.wValue); in xudc_ep0_in()
1886 if (udc->setup.bRequestType == in xudc_ep0_in()
1888 if (udc->setup.wValue == in xudc_ep0_in()
1890 udc->write_fn(udc->addr, in xudc_ep0_in()
1906 epcfgreg = udc->read_fn(udc->addr + ep0->offset); in xudc_ep0_in()
1908 udc->write_fn(udc->addr, ep0->offset, epcfgreg); in xudc_ep0_in()
1909 udc->setupseqtx = STATUS_PHASE; in xudc_ep0_in()
1914 ep0rambase = (u8 __force *) (udc->addr + in xudc_ep0_in()
1920 udc->write_fn(udc->addr, XUSB_EP_BUF0COUNT_OFFSET, count); in xudc_ep0_in()
1921 udc->write_fn(udc->addr, XUSB_BUFFREADY_OFFSET, 1); in xudc_ep0_in()
1935 static void xudc_ctrl_ep_handler(struct xusb_udc *udc, u32 intrstatus) in xudc_ctrl_ep_handler() argument
1939 xudc_handle_setup(udc); in xudc_ctrl_ep_handler()
1942 xudc_ep0_out(udc); in xudc_ctrl_ep_handler()
1944 xudc_ep0_in(udc); in xudc_ctrl_ep_handler()
1957 static void xudc_nonctrl_ep_handler(struct xusb_udc *udc, u8 epnum, in xudc_nonctrl_ep_handler() argument
1964 ep = &udc->ep[epnum]; in xudc_nonctrl_ep_handler()
1991 struct xusb_udc *udc = _udc; in xudc_irq() local
1998 spin_lock_irqsave(&udc->lock, flags); in xudc_irq()
2004 ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_irq()
2006 udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); in xudc_irq()
2009 intrstatus = udc->read_fn(udc->addr + XUSB_STATUS_OFFSET); in xudc_irq()
2020 xudc_startup_handler(udc, intrstatus); in xudc_irq()
2026 ier = udc->read_fn(udc->addr + XUSB_IER_OFFSET); in xudc_irq()
2028 udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); in xudc_irq()
2031 xudc_ctrl_ep_handler(udc, intrstatus); in xudc_irq()
2040 xudc_nonctrl_ep_handler(udc, index, in xudc_irq()
2046 spin_unlock_irqrestore(&udc->lock, flags); in xudc_irq()
2060 struct xusb_udc *udc; in xudc_probe() local
2066 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); in xudc_probe()
2067 if (!udc) in xudc_probe()
2071 udc->req = devm_kzalloc(&pdev->dev, sizeof(struct xusb_req), in xudc_probe()
2073 if (!udc->req) in xudc_probe()
2080 udc->req->usb_req.buf = buff; in xudc_probe()
2084 udc->addr = devm_ioremap_resource(&pdev->dev, res); in xudc_probe()
2085 if (IS_ERR(udc->addr)) in xudc_probe()
2086 return PTR_ERR(udc->addr); in xudc_probe()
2092 dev_name(&pdev->dev), udc); in xudc_probe()
2098 udc->dma_enabled = of_property_read_bool(np, "xlnx,has-builtin-dma"); in xudc_probe()
2101 udc->gadget.ops = &xusb_udc_ops; in xudc_probe()
2102 udc->gadget.max_speed = USB_SPEED_HIGH; in xudc_probe()
2103 udc->gadget.speed = USB_SPEED_UNKNOWN; in xudc_probe()
2104 udc->gadget.ep0 = &udc->ep[XUSB_EP_NUMBER_ZERO].ep_usb; in xudc_probe()
2105 udc->gadget.name = driver_name; in xudc_probe()
2107 udc->clk = devm_clk_get(&pdev->dev, "s_axi_aclk"); in xudc_probe()
2108 if (IS_ERR(udc->clk)) { in xudc_probe()
2109 if (PTR_ERR(udc->clk) != -ENOENT) { in xudc_probe()
2110 ret = PTR_ERR(udc->clk); in xudc_probe()
2119 udc->clk = NULL; in xudc_probe()
2122 ret = clk_prepare_enable(udc->clk); in xudc_probe()
2128 spin_lock_init(&udc->lock); in xudc_probe()
2131 udc->write_fn = xudc_write32_be; in xudc_probe()
2132 udc->read_fn = xudc_read32_be; in xudc_probe()
2133 udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, USB_TEST_J); in xudc_probe()
2134 if ((udc->read_fn(udc->addr + XUSB_TESTMODE_OFFSET)) in xudc_probe()
2136 udc->write_fn = xudc_write32; in xudc_probe()
2137 udc->read_fn = xudc_read32; in xudc_probe()
2139 udc->write_fn(udc->addr, XUSB_TESTMODE_OFFSET, 0); in xudc_probe()
2141 xudc_eps_init(udc); in xudc_probe()
2144 udc->write_fn(udc->addr, XUSB_ADDRESS_OFFSET, 0); in xudc_probe()
2146 ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); in xudc_probe()
2150 udc->dev = &udc->gadget.dev; in xudc_probe()
2158 udc->write_fn(udc->addr, XUSB_IER_OFFSET, ier); in xudc_probe()
2160 platform_set_drvdata(pdev, udc); in xudc_probe()
2163 driver_name, (u32)res->start, udc->addr, in xudc_probe()
2164 udc->dma_enabled ? "with DMA" : "without DMA"); in xudc_probe()
2169 clk_disable_unprepare(udc->clk); in xudc_probe()
2183 struct xusb_udc *udc = platform_get_drvdata(pdev); in xudc_remove() local
2185 usb_del_gadget_udc(&udc->gadget); in xudc_remove()
2186 clk_disable_unprepare(udc->clk); in xudc_remove()
2194 struct xusb_udc *udc; in xudc_suspend() local
2198 udc = dev_get_drvdata(dev); in xudc_suspend()
2200 spin_lock_irqsave(&udc->lock, flags); in xudc_suspend()
2202 crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); in xudc_suspend()
2205 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_suspend()
2207 spin_unlock_irqrestore(&udc->lock, flags); in xudc_suspend()
2208 if (udc->driver && udc->driver->suspend) in xudc_suspend()
2209 udc->driver->suspend(&udc->gadget); in xudc_suspend()
2211 clk_disable(udc->clk); in xudc_suspend()
2218 struct xusb_udc *udc; in xudc_resume() local
2223 udc = dev_get_drvdata(dev); in xudc_resume()
2225 ret = clk_enable(udc->clk); in xudc_resume()
2229 spin_lock_irqsave(&udc->lock, flags); in xudc_resume()
2231 crtlreg = udc->read_fn(udc->addr + XUSB_CONTROL_OFFSET); in xudc_resume()
2234 udc->write_fn(udc->addr, XUSB_CONTROL_OFFSET, crtlreg); in xudc_resume()
2236 spin_unlock_irqrestore(&udc->lock, flags); in xudc_resume()