Lines Matching +full:dbg +full:- +full:halt
1 // SPDX-License-Identifier: GPL-2.0+
3 * Intel PXA25x and IXP4xx on-chip full speed USB device controllers
30 #include <linux/dma-mapping.h>
40 #include <asm/mach-types.h>
48 #define UDC_RES1 0x0004 /* UDC Undocumented - Reserved1 */
49 #define UDC_RES2 0x0008 /* UDC Undocumented - Reserved2 */
50 #define UDC_RES3 0x000C /* UDC Undocumented - Reserved3 */
211 * not used here. IN-DMA (to host) is simple enough, when the data is
213 * other software can. OUT-DMA is buggy in most chip versions, as well
215 * bother using DMA. (Mostly-working IN-DMA support was available in
219 #define DRIVER_VERSION "30-June-2007"
230 /* cpu-specific register addresses are compiled in to this code */
252 /* ---------------------------------------------------------------------------
254 * used by gadget driver; and the inner talker-to-hardware core.
255 * ---------------------------------------------------------------------------
264 struct pxa2xx_udc_mach_info *mach = the_controller->mach; in pullup_off()
265 int off_level = mach->gpio_pullup_inverted; in pullup_off()
267 if (gpio_is_valid(mach->gpio_pullup)) in pullup_off()
268 gpio_set_value(mach->gpio_pullup, off_level); in pullup_off()
269 else if (mach->udc_command) in pullup_off()
270 mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); in pullup_off()
275 struct pxa2xx_udc_mach_info *mach = the_controller->mach; in pullup_on()
276 int on_level = !mach->gpio_pullup_inverted; in pullup_on()
278 if (gpio_is_valid(mach->gpio_pullup)) in pullup_on()
279 gpio_set_value(mach->gpio_pullup, on_level); in pullup_on()
280 else if (mach->udc_command) in pullup_on()
281 mach->udc_command(PXA2XX_UDC_CMD_CONNECT); in pullup_on()
287 * byte swaps, independent of whether it runs in big-endian or little-endian
290 * We only support pxa25x in little-endian mode, but it is very likely
295 iowrite32be(val, dev->regs + reg); in udc_set_reg()
300 return ioread32be(dev->regs + reg); in udc_get_reg()
305 writel(val, dev->regs + reg); in udc_set_reg()
310 return readl(dev->regs + reg); in udc_get_reg()
316 u32 bEndpointAddress = ep->bEndpointAddress & 0xf; in pio_irq_enable()
319 udc_set_reg(ep->dev, UICR0, udc_get_reg(ep->dev, UICR0) & in pio_irq_enable()
322 bEndpointAddress -= 8; in pio_irq_enable()
323 udc_set_reg(ep->dev, UICR1, udc_get_reg(ep->dev, UICR1) & in pio_irq_enable()
330 u32 bEndpointAddress = ep->bEndpointAddress & 0xf; in pio_irq_disable()
333 udc_set_reg(ep->dev, UICR0, udc_get_reg(ep->dev, UICR0) | in pio_irq_disable()
336 bEndpointAddress -= 8; in pio_irq_disable()
337 udc_set_reg(ep->dev, UICR1, udc_get_reg(ep->dev, UICR1) | in pio_irq_disable()
371 return udc_get_reg(ep->dev, ep->regoff_udccs); in udc_ep_get_UDCCS()
376 udc_set_reg(ep->dev, data, ep->regoff_udccs); in udc_ep_set_UDCCS()
391 return udc_get_reg(ep->dev, ep->regoff_uddr); in udc_ep_get_UDDR()
396 udc_set_reg(ep->dev, data, ep->regoff_uddr); in udc_ep_set_UDDR()
401 return udc_get_reg(ep->dev, ep->regoff_ubcr); in udc_ep_get_UBCR()
412 * (resetting endpoint halt and toggle), SET_INTERFACE is unusable except
414 * drivers that don't halt endpoints (not reset by set_interface). that also
416 * iso endpoints must be in non-default altsettings.
425 if (!_ep || !desc || _ep->name == ep0name in pxa25x_ep_enable()
426 || desc->bDescriptorType != USB_DT_ENDPOINT in pxa25x_ep_enable()
427 || ep->bEndpointAddress != desc->bEndpointAddress in pxa25x_ep_enable()
428 || ep->fifo_size < usb_endpoint_maxp (desc)) { in pxa25x_ep_enable()
430 return -EINVAL; in pxa25x_ep_enable()
434 if (ep->bmAttributes != desc->bmAttributes in pxa25x_ep_enable()
435 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK in pxa25x_ep_enable()
436 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { in pxa25x_ep_enable()
437 DMSG("%s, %s type mismatch\n", __func__, _ep->name); in pxa25x_ep_enable()
438 return -EINVAL; in pxa25x_ep_enable()
442 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK in pxa25x_ep_enable()
445 || !desc->wMaxPacketSize) { in pxa25x_ep_enable()
446 DMSG("%s, bad %s maxpacket\n", __func__, _ep->name); in pxa25x_ep_enable()
447 return -ERANGE; in pxa25x_ep_enable()
450 dev = ep->dev; in pxa25x_ep_enable()
451 if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) { in pxa25x_ep_enable()
453 return -ESHUTDOWN; in pxa25x_ep_enable()
456 ep->ep.desc = desc; in pxa25x_ep_enable()
457 ep->stopped = 0; in pxa25x_ep_enable()
458 ep->pio_irqs = 0; in pxa25x_ep_enable()
459 ep->ep.maxpacket = usb_endpoint_maxp (desc); in pxa25x_ep_enable()
464 /* ... reset halt state too, if we could ... */ in pxa25x_ep_enable()
466 DBG(DBG_VERBOSE, "enabled %s\n", _ep->name); in pxa25x_ep_enable()
476 if (!_ep || !ep->ep.desc) { in pxa25x_ep_disable()
478 _ep ? ep->ep.name : NULL); in pxa25x_ep_disable()
479 return -EINVAL; in pxa25x_ep_disable()
483 nuke (ep, -ESHUTDOWN); in pxa25x_ep_disable()
488 ep->ep.desc = NULL; in pxa25x_ep_disable()
489 ep->stopped = 1; in pxa25x_ep_disable()
492 DBG(DBG_VERBOSE, "%s disabled\n", _ep->name); in pxa25x_ep_disable()
496 /*-------------------------------------------------------------------------*/
504 * pxa25x_ep_alloc_request - allocate a request data structure
515 INIT_LIST_HEAD (&req->queue); in pxa25x_ep_alloc_request()
516 return &req->req; in pxa25x_ep_alloc_request()
521 * pxa25x_ep_free_request - deallocate a request data structure
529 WARN_ON(!list_empty (&req->queue)); in pxa25x_ep_free_request()
533 /*-------------------------------------------------------------------------*/
536 * done - retire a request; caller blocked irqs
540 unsigned stopped = ep->stopped; in done()
542 list_del_init(&req->queue); in done()
544 if (likely (req->req.status == -EINPROGRESS)) in done()
545 req->req.status = status; in done()
547 status = req->req.status; in done()
549 if (status && status != -ESHUTDOWN) in done()
550 DBG(DBG_VERBOSE, "complete %s req %p stat %d len %u/%u\n", in done()
551 ep->ep.name, &req->req, status, in done()
552 req->req.actual, req->req.length); in done()
555 ep->stopped = 1; in done()
556 usb_gadget_giveback_request(&ep->ep, &req->req); in done()
557 ep->stopped = stopped; in done()
563 dev->ep0state = EP0_IDLE; in ep0_idle()
572 buf = req->req.buf + req->req.actual; in write_packet()
576 length = min(req->req.length - req->req.actual, max); in write_packet()
577 req->req.actual += length; in write_packet()
580 while (likely(count--)) in write_packet()
596 max = usb_endpoint_maxp(ep->ep.desc); in write_fifo()
607 if (likely(req->req.length != req->req.actual) in write_fifo()
608 || req->req.zero) in write_fifo()
613 is_short = unlikely (max < ep->fifo_size); in write_fifo()
616 DBG(DBG_VERY_NOISY, "wrote %s %d bytes%s%s %d left %p\n", in write_fifo()
617 ep->ep.name, count, in write_fifo()
619 req->req.length - req->req.actual, req); in write_fifo()
632 if (list_empty(&ep->queue)) in write_fifo()
645 /* caller asserts req->pending (ep0 irq status nyet cleared); starts
653 dev->req_pending = 0; in ep0start()
654 DBG(DBG_VERY_NOISY, "%s %s, %02x/%02x\n", in ep0start()
661 struct pxa25x_udc *dev = ep->dev; in write_ep0_fifo()
665 count = write_packet(&dev->ep[0], req, EP0_FIFO_SIZE); in write_ep0_fifo()
666 ep->dev->stats.write.bytes += count; in write_ep0_fifo()
671 DBG(DBG_VERY_NOISY, "ep0in %d bytes %d left %p\n", count, in write_ep0_fifo()
672 req->req.length - req->req.actual, req); in write_ep0_fifo()
675 if (ep->dev->req_pending) in write_ep0_fifo()
676 ep0start(ep->dev, UDCCS0_IPR, "short IN"); in write_ep0_fifo()
680 count = req->req.length; in write_ep0_fifo()
682 ep0_idle(ep->dev); in write_ep0_fifo()
699 count--; in write_ep0_fifo()
705 } else if (ep->dev->req_pending) in write_ep0_fifo()
706 ep0start(ep->dev, 0, "IN"); in write_ep0_fifo()
712 * read_fifo - unload packet(s) from the fifo we use for usb OUT
717 * request buffer having filled (and maybe overran till end-of-packet).
734 buf = req->req.buf + req->req.actual; in read_fifo()
736 bufferspace = req->req.length - req->req.actual; in read_fifo()
741 req->req.actual += min (count, bufferspace); in read_fifo()
744 is_short = (count < ep->ep.maxpacket); in read_fifo()
745 DBG(DBG_VERY_NOISY, "read %s %02x, %d bytes%s req %p %d/%d\n", in read_fifo()
746 ep->ep.name, udccs, count, in read_fifo()
748 req, req->req.actual, req->req.length); in read_fifo()
749 while (likely (count-- != 0)) { in read_fifo()
757 if (req->req.status != -EOVERFLOW) in read_fifo()
759 ep->ep.name, count); in read_fifo()
760 req->req.status = -EOVERFLOW; in read_fifo()
763 bufferspace--; in read_fifo()
770 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { in read_fifo()
772 req->req.status = -EHOSTUNREACH; in read_fifo()
778 if (is_short || req->req.actual == req->req.length) { in read_fifo()
780 if (list_empty(&ep->queue)) in read_fifo()
792 * handshaking is magic. most device protocols don't need control-OUT.
802 buf = req->req.buf + req->req.actual; in read_ep0_fifo()
803 bufferspace = req->req.length - req->req.actual; in read_ep0_fifo()
813 if (req->req.status != -EOVERFLOW) in read_ep0_fifo()
814 DMSG("%s overflow\n", ep->ep.name); in read_ep0_fifo()
815 req->req.status = -EOVERFLOW; in read_ep0_fifo()
818 req->req.actual++; in read_ep0_fifo()
819 bufferspace--; in read_ep0_fifo()
826 if (req->req.actual >= req->req.length) in read_ep0_fifo()
833 /*-------------------------------------------------------------------------*/
844 if (unlikely (!_req || !_req->complete || !_req->buf in pxa25x_ep_queue()
845 || !list_empty(&req->queue))) { in pxa25x_ep_queue()
847 return -EINVAL; in pxa25x_ep_queue()
851 if (unlikely(!_ep || (!ep->ep.desc && ep->ep.name != ep0name))) { in pxa25x_ep_queue()
853 return -EINVAL; in pxa25x_ep_queue()
856 dev = ep->dev; in pxa25x_ep_queue()
857 if (unlikely (!dev->driver in pxa25x_ep_queue()
858 || dev->gadget.speed == USB_SPEED_UNKNOWN)) { in pxa25x_ep_queue()
860 return -ESHUTDOWN; in pxa25x_ep_queue()
864 * we can report per-packet status. that also helps with dma. in pxa25x_ep_queue()
866 if (unlikely (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC in pxa25x_ep_queue()
867 && req->req.length > usb_endpoint_maxp(ep->ep.desc))) in pxa25x_ep_queue()
868 return -EMSGSIZE; in pxa25x_ep_queue()
870 DBG(DBG_NOISY, "%s queue req %p, len %d buf %p\n", in pxa25x_ep_queue()
871 _ep->name, _req, _req->length, _req->buf); in pxa25x_ep_queue()
875 _req->status = -EINPROGRESS; in pxa25x_ep_queue()
876 _req->actual = 0; in pxa25x_ep_queue()
879 if (list_empty(&ep->queue) && !ep->stopped) { in pxa25x_ep_queue()
880 if (ep->ep.desc == NULL/* ep0 */) { in pxa25x_ep_queue()
881 unsigned length = _req->length; in pxa25x_ep_queue()
883 switch (dev->ep0state) { in pxa25x_ep_queue()
885 dev->stats.write.ops++; in pxa25x_ep_queue()
891 dev->stats.read.ops++; in pxa25x_ep_queue()
893 if (dev->req_config) { in pxa25x_ep_queue()
894 DBG(DBG_VERBOSE, "ep0 config ack%s\n", in pxa25x_ep_queue()
895 dev->has_cfr ? "" : " raced"); in pxa25x_ep_queue()
896 if (dev->has_cfr) in pxa25x_ep_queue()
900 dev->ep0state = EP0_END_XFER; in pxa25x_ep_queue()
904 if (dev->req_pending) in pxa25x_ep_queue()
915 DMSG("ep0 i/o, odd state %d\n", dev->ep0state); in pxa25x_ep_queue()
917 return -EL2HLT; in pxa25x_ep_queue()
920 } else if ((ep->bEndpointAddress & USB_DIR_IN) != 0) { in pxa25x_ep_queue()
929 if (likely(req && ep->ep.desc)) in pxa25x_ep_queue()
935 list_add_tail(&req->queue, &ep->queue); in pxa25x_ep_queue()
943 * nuke - dequeue ALL requests
950 while (!list_empty(&ep->queue)) { in nuke()
951 req = list_entry(ep->queue.next, in nuke()
956 if (ep->ep.desc) in nuke()
970 if (!_ep || ep->ep.name == ep0name) in pxa25x_ep_dequeue()
971 return -EINVAL; in pxa25x_ep_dequeue()
976 list_for_each_entry(iter, &ep->queue, queue) { in pxa25x_ep_dequeue()
977 if (&iter->req != _req) in pxa25x_ep_dequeue()
984 return -EINVAL; in pxa25x_ep_dequeue()
987 done(ep, req, -ECONNRESET); in pxa25x_ep_dequeue()
993 /*-------------------------------------------------------------------------*/
1002 || (!ep->ep.desc && ep->ep.name != ep0name)) in pxa25x_ep_set_halt()
1003 || ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { in pxa25x_ep_set_halt()
1005 return -EINVAL; in pxa25x_ep_set_halt()
1008 /* this path (reset toggle+halt) is needed to implement in pxa25x_ep_set_halt()
1013 DMSG("only host can clear %s halt\n", _ep->name); in pxa25x_ep_set_halt()
1014 return -EROFS; in pxa25x_ep_set_halt()
1019 if ((ep->bEndpointAddress & USB_DIR_IN) != 0 in pxa25x_ep_set_halt()
1021 || !list_empty(&ep->queue))) { in pxa25x_ep_set_halt()
1023 return -EAGAIN; in pxa25x_ep_set_halt()
1030 if (!ep->ep.desc) { in pxa25x_ep_set_halt()
1031 start_watchdog(ep->dev); in pxa25x_ep_set_halt()
1032 ep->dev->req_pending = 0; in pxa25x_ep_set_halt()
1033 ep->dev->ep0state = EP0_STALL; in pxa25x_ep_set_halt()
1046 DBG(DBG_VERBOSE, "%s halt\n", _ep->name); in pxa25x_ep_set_halt()
1057 return -ENODEV; in pxa25x_ep_fifo_status()
1060 if ((ep->bEndpointAddress & USB_DIR_IN) != 0) in pxa25x_ep_fifo_status()
1061 return -EOPNOTSUPP; in pxa25x_ep_fifo_status()
1062 if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN in pxa25x_ep_fifo_status()
1074 if (!_ep || ep->ep.name == ep0name || !list_empty(&ep->queue)) { in pxa25x_ep_fifo_flush()
1079 /* toggle and halt bits stay unchanged */ in pxa25x_ep_fifo_flush()
1082 if ((ep->bEndpointAddress & USB_DIR_IN) == 0) { in pxa25x_ep_fifo_flush()
1090 | (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC in pxa25x_ep_fifo_flush()
1111 /* ---------------------------------------------------------------------------
1112 * device-scoped parts of the api to the usb controller hardware
1113 * ---------------------------------------------------------------------------
1133 return -EHOSTUNREACH; in pxa25x_udc_wakeup()
1142 /* We disable the UDC -- and its 48 MHz clock -- whenever it's not
1147 int is_active = udc->vbus && udc->pullup && !udc->suspended; in pullup()
1150 if (!udc->active) { in pullup()
1151 udc->active = 1; in pullup()
1153 clk_enable(udc->clk); in pullup()
1157 if (udc->active) { in pullup()
1158 if (udc->gadget.speed != USB_SPEED_UNKNOWN) { in pullup()
1159 DMSG("disconnect %s\n", udc->driver in pullup()
1160 ? udc->driver->driver.name in pullup()
1162 stop_activity(udc, udc->driver); in pullup()
1166 clk_disable(udc->clk); in pullup()
1167 udc->active = 0; in pullup()
1180 udc->vbus = is_active; in pxa25x_udc_vbus_session()
1194 if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command) in pxa25x_udc_pullup()
1195 return -EOPNOTSUPP; in pxa25x_udc_pullup()
1197 udc->pullup = (is_active != 0); in pxa25x_udc_pullup()
1202 /* boards may consume current from VBUS, up to 100-500mA based on config.
1203 * the 500uA suspend ceiling means that exclusively vbus-powered PXA designs
1212 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa25x_udc_vbus_draw()
1213 return usb_phy_set_power(udc->transceiver, mA); in pxa25x_udc_vbus_draw()
1214 return -EOPNOTSUPP; in pxa25x_udc_vbus_draw()
1231 /*-------------------------------------------------------------------------*/
1237 struct pxa25x_udc *dev = m->private; in udc_debug_show()
1248 dev->driver ? dev->driver->driver.name : "(none)", in udc_debug_show()
1249 dev->gadget.speed == USB_SPEED_FULL ? "full speed" : "disconnected"); in udc_debug_show()
1282 if (dev->has_cfr) { in udc_debug_show()
1290 if (dev->gadget.speed != USB_SPEED_FULL || !dev->driver) in udc_debug_show()
1294 dev->stats.write.bytes, dev->stats.write.ops, in udc_debug_show()
1295 dev->stats.read.bytes, dev->stats.read.ops, in udc_debug_show()
1296 dev->stats.irqs); in udc_debug_show()
1300 struct pxa25x_ep *ep = &dev->ep [i]; in udc_debug_show()
1306 desc = ep->ep.desc; in udc_debug_show()
1309 tmp = udc_ep_get_UDCCS(&dev->ep[i]); in udc_debug_show()
1312 ep->ep.name, usb_endpoint_maxp(desc), in udc_debug_show()
1313 "pio", tmp, ep->pio_irqs); in udc_debug_show()
1318 ep->pio_irqs); in udc_debug_show()
1320 if (list_empty(&ep->queue)) { in udc_debug_show()
1324 list_for_each_entry(req, &ep->queue, queue) { in udc_debug_show()
1327 &req->req, req->req.actual, in udc_debug_show()
1328 req->req.length, req->req.buf); in udc_debug_show()
1340 debugfs_create_file(dev->gadget.name, \
1343 #define remove_debug_files(dev) debugfs_lookup_and_remove(dev->gadget.name, NULL)
1352 /*-------------------------------------------------------------------------*/
1355 * udc_disable - disable USB device controller
1371 dev->gadget.speed = USB_SPEED_UNKNOWN; in udc_disable()
1376 * udc_reinit - initialize software state
1383 INIT_LIST_HEAD (&dev->gadget.ep_list); in udc_reinit()
1384 INIT_LIST_HEAD (&dev->gadget.ep0->ep_list); in udc_reinit()
1385 dev->ep0state = EP0_IDLE; in udc_reinit()
1386 dev->gadget.quirk_altset_not_supp = 1; in udc_reinit()
1390 struct pxa25x_ep *ep = &dev->ep[i]; in udc_reinit()
1393 list_add_tail (&ep->ep.ep_list, &dev->gadget.ep_list); in udc_reinit()
1395 ep->ep.desc = NULL; in udc_reinit()
1396 ep->stopped = 0; in udc_reinit()
1397 INIT_LIST_HEAD (&ep->queue); in udc_reinit()
1398 ep->pio_irqs = 0; in udc_reinit()
1399 usb_ep_set_maxpacket_limit(&ep->ep, ep->ep.maxpacket); in udc_reinit()
1402 /* the rest was statically initialized, and is read-only */ in udc_reinit()
1416 dev->gadget.speed = USB_SPEED_UNKNOWN; in udc_enable()
1417 dev->stats.irqs = 0; in udc_enable()
1421 * - enable UDC in udc_enable()
1422 * - if RESET is already in progress, ack interrupt in udc_enable()
1423 * - unmask reset interrupt in udc_enable()
1429 if (dev->has_cfr /* UDC_RES2 is defined */) { in udc_enable()
1435 /* "USB test mode" for pxa250 errata 40-42 (stepping a0, a1) in udc_enable()
1458 * non-control requests. then usb traffic follows until a
1469 dev->driver = driver; in pxa25x_udc_start()
1470 dev->pullup = 1; in pxa25x_udc_start()
1476 if (!IS_ERR_OR_NULL(dev->transceiver)) { in pxa25x_udc_start()
1477 retval = otg_set_peripheral(dev->transceiver->otg, in pxa25x_udc_start()
1478 &dev->gadget); in pxa25x_udc_start()
1495 if (dev->gadget.speed == USB_SPEED_UNKNOWN) in reset_gadget()
1497 dev->gadget.speed = USB_SPEED_UNKNOWN; in reset_gadget()
1501 struct pxa25x_ep *ep = &dev->ep[i]; in reset_gadget()
1503 ep->stopped = 1; in reset_gadget()
1504 nuke(ep, -ESHUTDOWN); in reset_gadget()
1506 del_timer_sync(&dev->timer); in reset_gadget()
1510 usb_gadget_udc_reset(&dev->gadget, driver); in reset_gadget()
1512 /* re-init driver-visible data structures */ in reset_gadget()
1522 if (dev->gadget.speed == USB_SPEED_UNKNOWN) in stop_activity()
1524 dev->gadget.speed = USB_SPEED_UNKNOWN; in stop_activity()
1528 struct pxa25x_ep *ep = &dev->ep[i]; in stop_activity()
1530 ep->stopped = 1; in stop_activity()
1531 nuke(ep, -ESHUTDOWN); in stop_activity()
1533 del_timer_sync(&dev->timer); in stop_activity()
1537 driver->disconnect(&dev->gadget); in stop_activity()
1539 /* re-init driver-visible data structures */ in stop_activity()
1548 dev->pullup = 0; in pxa25x_udc_stop()
1552 if (!IS_ERR_OR_NULL(dev->transceiver)) in pxa25x_udc_stop()
1553 (void) otg_set_peripheral(dev->transceiver->otg, NULL); in pxa25x_udc_stop()
1555 dev->driver = NULL; in pxa25x_udc_stop()
1562 /*-------------------------------------------------------------------------*/
1572 nuke(&dev->ep[i], -ECONNABORTED); in clear_ep_state()
1580 if (dev->ep0state == EP0_STALL in udc_watchdog()
1584 DBG(DBG_VERBOSE, "ep0 re-stall\n"); in udc_watchdog()
1593 struct pxa25x_ep *ep = &dev->ep [0]; in handle_ep0()
1601 if (list_empty(&ep->queue)) in handle_ep0()
1604 req = list_entry(ep->queue.next, struct pxa25x_request, queue); in handle_ep0()
1608 nuke(ep, -EPIPE); in handle_ep0()
1610 del_timer(&dev->timer); in handle_ep0()
1614 /* previous request unfinished? non-error iff back-to-back ... */ in handle_ep0()
1615 if ((udccs0 & UDCCS0_SA) != 0 && dev->ep0state != EP0_IDLE) { in handle_ep0()
1617 del_timer(&dev->timer); in handle_ep0()
1621 switch (dev->ep0state) { in handle_ep0()
1623 /* late-breaking status? */ in handle_ep0()
1631 nuke (ep, -EPROTO); in handle_ep0()
1646 DBG(DBG_VERBOSE, "SETUP %02x.%02x v%04x i%04x l%04x\n", in handle_ep0()
1653 dev->req_std = (u.r.bRequestType & USB_TYPE_MASK) in handle_ep0()
1655 dev->req_config = 0; in handle_ep0()
1656 dev->req_pending = 1; in handle_ep0()
1665 dev->req_config = 1; in handle_ep0()
1677 * - altsetting may only be zero; in handle_ep0()
1678 * - hw resets all interfaces' eps; in handle_ep0()
1679 * - ep reset doesn't include halt(?). in handle_ep0()
1697 dev->ep0state = EP0_IN_DATA_PHASE; in handle_ep0()
1699 dev->ep0state = EP0_OUT_DATA_PHASE; in handle_ep0()
1701 i = dev->driver->setup(&dev->gadget, &u.r); in handle_ep0()
1704 if (dev->req_config) { in handle_ep0()
1717 DBG(DBG_VERBOSE, "protocol STALL, " in handle_ep0()
1726 dev->ep0state = EP0_STALL; in handle_ep0()
1729 } else if (dev->req_pending) { in handle_ep0()
1730 if (likely(dev->ep0state == EP0_IN_DATA_PHASE in handle_ep0()
1731 || dev->req_std || u.r.wLength)) in handle_ep0()
1747 DBG(DBG_VERBOSE, "e131\n"); in handle_ep0()
1748 nuke(ep, -EPROTO); in handle_ep0()
1761 * - we acked FST in handle_ep0()
1762 * - IPR cleared in handle_ep0()
1763 * - OPR got set, without SA (likely status stage) in handle_ep0()
1771 DBG(DBG_VERBOSE, "ep0in premature status\n"); in handle_ep0()
1791 DBG(DBG_VERBOSE, "ep0out premature status\n"); in handle_ep0()
1800 /* ack control-IN status (maybe in-zlp was skipped) in handle_ep0()
1817 int is_in = ep->bEndpointAddress & USB_DIR_IN; in handle_ep()
1823 if (likely (!list_empty(&ep->queue))) in handle_ep()
1824 req = list_entry(ep->queue.next, in handle_ep()
1834 if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK)) in handle_ep()
1843 if (likely(ep->bmAttributes == USB_ENDPOINT_XFER_BULK)) in handle_ep()
1857 ep->pio_irqs++; in handle_ep()
1862 * pxa25x_udc_irq - interrupt handler
1874 dev->stats.irqs++; in pxa25x_udc_irq()
1884 DBG(DBG_VERBOSE, "USB suspend\n"); in pxa25x_udc_irq()
1886 if (dev->gadget.speed != USB_SPEED_UNKNOWN in pxa25x_udc_irq()
1887 && dev->driver in pxa25x_udc_irq()
1888 && dev->driver->suspend) in pxa25x_udc_irq()
1889 dev->driver->suspend(&dev->gadget); in pxa25x_udc_irq()
1897 DBG(DBG_VERBOSE, "USB resume\n"); in pxa25x_udc_irq()
1899 if (dev->gadget.speed != USB_SPEED_UNKNOWN in pxa25x_udc_irq()
1900 && dev->driver in pxa25x_udc_irq()
1901 && dev->driver->resume) in pxa25x_udc_irq()
1902 dev->driver->resume(&dev->gadget); in pxa25x_udc_irq()
1905 /* ReSeT Interrupt Request - USB reset */ in pxa25x_udc_irq()
1911 DBG(DBG_VERBOSE, "USB reset start\n"); in pxa25x_udc_irq()
1916 reset_gadget(dev, dev->driver); in pxa25x_udc_irq()
1919 DBG(DBG_VERBOSE, "USB reset end\n"); in pxa25x_udc_irq()
1920 dev->gadget.speed = USB_SPEED_FULL; in pxa25x_udc_irq()
1921 memset(&dev->stats, 0, sizeof dev->stats); in pxa25x_udc_irq()
1935 DBG(DBG_VERY_NOISY, "irq %02x.%02x\n", usir1, usir0); in pxa25x_udc_irq()
1939 dev->ep[0].pio_irqs++; in pxa25x_udc_irq()
1949 handle_ep(&dev->ep[i]); in pxa25x_udc_irq()
1956 handle_ep(&dev->ep[i+8]); in pxa25x_udc_irq()
1971 /*-------------------------------------------------------------------------*/
1978 /* this uses load-time allocation and initialization (instead of
1979 * doing it at run-time) to save code, eliminate fault paths, and
2010 .name = "ep1in-bulk",
2025 .name = "ep2out-bulk",
2042 .name = "ep3in-iso",
2057 .name = "ep4out-iso",
2073 .name = "ep5in-int",
2089 .name = "ep6in-bulk",
2104 .name = "ep7out-bulk",
2120 .name = "ep8in-iso",
2135 .name = "ep9out-iso",
2151 .name = "ep10in-int",
2167 .name = "ep11in-bulk",
2182 .name = "ep12out-bulk",
2198 .name = "ep13in-iso",
2213 .name = "ep14out-iso",
2229 .name = "ep15in-int",
2279 * probe - binds to the platform device
2293 return -ENODEV; in pxa25x_udc_probe()
2296 /* trigger chiprev-specific logic */ in pxa25x_udc_probe()
2300 dev->has_cfr = 1; in pxa25x_udc_probe()
2309 /* OUT-DMA is broken ... */ in pxa25x_udc_probe()
2317 dev->has_cfr = 1; in pxa25x_udc_probe()
2324 return -ENODEV; in pxa25x_udc_probe()
2331 dev->regs = devm_platform_ioremap_resource(pdev, 0); in pxa25x_udc_probe()
2332 if (IS_ERR(dev->regs)) in pxa25x_udc_probe()
2333 return PTR_ERR(dev->regs); in pxa25x_udc_probe()
2335 dev->clk = devm_clk_get(&pdev->dev, NULL); in pxa25x_udc_probe()
2336 if (IS_ERR(dev->clk)) in pxa25x_udc_probe()
2337 return PTR_ERR(dev->clk); in pxa25x_udc_probe()
2340 dev->has_cfr ? "" : " (!cfr)", in pxa25x_udc_probe()
2344 /* other non-static parts of init */ in pxa25x_udc_probe()
2345 dev->dev = &pdev->dev; in pxa25x_udc_probe()
2346 dev->mach = dev_get_platdata(&pdev->dev); in pxa25x_udc_probe()
2348 dev->transceiver = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2); in pxa25x_udc_probe()
2350 if (gpio_is_valid(dev->mach->gpio_pullup)) { in pxa25x_udc_probe()
2351 retval = devm_gpio_request(&pdev->dev, dev->mach->gpio_pullup, in pxa25x_udc_probe()
2354 dev_dbg(&pdev->dev, in pxa25x_udc_probe()
2356 dev->mach->gpio_pullup, retval); in pxa25x_udc_probe()
2359 gpio_direction_output(dev->mach->gpio_pullup, 0); in pxa25x_udc_probe()
2362 timer_setup(&dev->timer, udc_watchdog, 0); in pxa25x_udc_probe()
2370 dev->vbus = 0; in pxa25x_udc_probe()
2373 retval = devm_request_irq(&pdev->dev, irq, pxa25x_udc_irq, 0, in pxa25x_udc_probe()
2380 dev->got_irq = 1; in pxa25x_udc_probe()
2384 retval = usb_add_gadget_udc(&pdev->dev, &dev->gadget); in pxa25x_udc_probe()
2390 if (!IS_ERR_OR_NULL(dev->transceiver)) in pxa25x_udc_probe()
2391 dev->transceiver = NULL; in pxa25x_udc_probe()
2404 if (dev->driver) { in pxa25x_udc_remove()
2405 dev_err(&pdev->dev, in pxa25x_udc_remove()
2410 usb_del_gadget_udc(&dev->gadget); in pxa25x_udc_remove()
2411 dev->pullup = 0; in pxa25x_udc_remove()
2416 if (!IS_ERR_OR_NULL(dev->transceiver)) in pxa25x_udc_remove()
2417 dev->transceiver = NULL; in pxa25x_udc_remove()
2422 /*-------------------------------------------------------------------------*/
2443 if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command) in pxa25x_udc_suspend()
2445 udc->suspended = 1; in pxa25x_udc_suspend()
2459 udc->suspended = 0; in pxa25x_udc_resume()
2472 /*-------------------------------------------------------------------------*/
2481 .name = "pxa25x-udc",
2490 MODULE_ALIAS("platform:pxa25x-udc");