Lines Matching +full:ls +full:- +full:oe

1 // SPDX-License-Identifier: GPL-2.0+
20 #include <linux/dma-mapping.h>
78 #define DATA_IN 1 /* Expect dev->host transfer */
79 #define DATA_OUT 2 /* Expect host->dev transfer */
161 /* USB device peripheral - various */
188 dev_dbg(epp->udc->dev, "%s: " fmt, __func__, ## arg)
190 dev_err(epp->udc->dev, "%s: " fmt, __func__, ## arg)
192 dev_info(epp->udc->dev, "%s: " fmt, __func__, ## arg)
194 dev_warn(epp->udc->dev, "%s:" fmt, __func__, ## arg)
345 #define DD_STATUS_LSB_EX 0x40 /* LS byte extracted (ATLE) */
479 ep->ep.name, ep->ep.maxpacket, in proc_ep_show()
480 ep->is_in ? "in" : "out"); in proc_ep_show()
481 seq_printf(s, " type %4s", epnames[ep->eptype]); in proc_ep_show()
482 seq_printf(s, " ints: %12d", ep->totalints); in proc_ep_show()
484 if (list_empty(&ep->queue)) in proc_ep_show()
487 list_for_each_entry(req, &ep->queue, queue) { in proc_ep_show()
488 u32 length = req->req.actual; in proc_ep_show()
491 &req->req, length, in proc_ep_show()
492 req->req.length, req->req.buf); in proc_ep_show()
499 struct lpc32xx_udc *udc = s->private; in udc_show()
505 spin_lock_irqsave(&udc->lock, flags); in udc_show()
508 udc->vbus ? "present" : "off", in udc_show()
509 udc->enabled ? (udc->vbus ? "active" : "enabled") : in udc_show()
511 udc->gadget.is_selfpowered ? "self" : "VBUS", in udc_show()
512 udc->suspended ? ", suspended" : "", in udc_show()
513 udc->driver ? udc->driver->driver.name : "(none)"); in udc_show()
515 if (udc->enabled && udc->vbus) { in udc_show()
516 proc_ep_show(s, &udc->ep[0]); in udc_show()
517 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) in udc_show()
521 spin_unlock_irqrestore(&udc->lock, flags); in udc_show()
549 vendor = i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x00); in isp1301_udc_configure()
550 product = i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x02); in isp1301_udc_configure()
553 udc->atx = STOTG04; in isp1301_udc_configure()
559 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
564 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
566 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
572 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
576 if (udc->atx != STOTG04) in isp1301_udc_configure()
578 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
582 if (udc->board->vbus_drv_pol != 0) in isp1301_udc_configure()
583 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
586 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
590 /* Bi-directional mode with suspend control in isp1301_udc_configure()
591 * Enable both pulldowns for now - the pullup will be enable when VBUS in isp1301_udc_configure()
593 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
595 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
600 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
603 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
607 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
610 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
612 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_udc_configure()
615 dev_info(udc->dev, "ISP1301 Vendor ID : 0x%04x\n", vendor); in isp1301_udc_configure()
616 dev_info(udc->dev, "ISP1301 Product ID : 0x%04x\n", product); in isp1301_udc_configure()
617 dev_info(udc->dev, "ISP1301 Version ID : 0x%04x\n", in isp1301_udc_configure()
618 i2c_smbus_read_word_data(udc->isp1301_i2c_client, 0x14)); in isp1301_udc_configure()
625 if (udc->pullup) in isp1301_pullup_set()
627 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_pullup_set()
631 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_pullup_set()
647 if (en_pullup == udc->pullup) in isp1301_pullup_enable()
650 udc->pullup = en_pullup; in isp1301_pullup_enable()
655 schedule_work(&udc->pullup_job); in isp1301_pullup_enable()
663 if (udc->atx == STOTG04) in isp1301_set_powerstate()
667 /* Power up ISP1301 - this ISP1301 will automatically wakeup in isp1301_set_powerstate()
669 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_set_powerstate()
674 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in isp1301_set_powerstate()
683 isp1301_set_powerstate(udc, udc->poweron); in power_work()
699 u32 tmp = readl(USBD_DEVINTST(udc->udp_baseaddr)); in udc_protocol_cmd_w()
703 writel(USBD_CCEMPTY, USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_protocol_cmd_w()
706 writel(cmd, USBD_CMDCODE(udc->udp_baseaddr)); in udc_protocol_cmd_w()
708 while (((readl(USBD_DEVINTST(udc->udp_baseaddr)) & in udc_protocol_cmd_w()
710 to--; in udc_protocol_cmd_w()
736 USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_protocol_cmd_r()
741 while ((!(readl(USBD_DEVINTST(udc->udp_baseaddr)) & USBD_CDFULL)) in udc_protocol_cmd_r()
743 to--; in udc_protocol_cmd_r()
745 dev_dbg(udc->dev, in udc_protocol_cmd_r()
748 return readl(USBD_CMDDATA(udc->udp_baseaddr)); in udc_protocol_cmd_r()
759 udc->enabled_devints |= devmask; in uda_enable_devint()
760 writel(udc->enabled_devints, USBD_DEVINTEN(udc->udp_baseaddr)); in uda_enable_devint()
766 udc->enabled_devints &= ~mask; in uda_disable_devint()
767 writel(udc->enabled_devints, USBD_DEVINTEN(udc->udp_baseaddr)); in uda_disable_devint()
773 writel(mask, USBD_DEVINTCLR(udc->udp_baseaddr)); in uda_clear_devint()
784 udc->enabled_hwepints |= (1 << hwep); in uda_enable_hwepint()
785 writel(udc->enabled_hwepints, USBD_EPINTEN(udc->udp_baseaddr)); in uda_enable_hwepint()
791 udc->enabled_hwepints &= ~(1 << hwep); in uda_disable_hwepint()
792 writel(udc->enabled_hwepints, USBD_EPINTEN(udc->udp_baseaddr)); in uda_disable_hwepint()
798 writel((1 << hwep), USBD_EPINTCLR(udc->udp_baseaddr)); in uda_clear_hwepint()
804 writel((1 << hwep), USBD_EPDMAEN(udc->udp_baseaddr)); in udc_ep_dma_enable()
810 writel((1 << hwep), USBD_EPDMADIS(udc->udp_baseaddr)); in udc_ep_dma_disable()
819 * in the USB protocol engine - this realizes the endpoint.
826 writel(USBD_EP_RLZED, USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_realize_hwep()
827 writel(hwep, USBD_EPIND(udc->udp_baseaddr)); in udc_realize_hwep()
828 udc->realized_eps |= (1 << hwep); in udc_realize_hwep()
829 writel(udc->realized_eps, USBD_REEP(udc->udp_baseaddr)); in udc_realize_hwep()
830 writel(maxpacket, USBD_EPMAXPSIZE(udc->udp_baseaddr)); in udc_realize_hwep()
833 while ((!(readl(USBD_DEVINTST(udc->udp_baseaddr)) & in udc_realize_hwep()
835 to--; in udc_realize_hwep()
837 dev_dbg(udc->dev, "EP not correctly realized in hardware\n"); in udc_realize_hwep()
839 writel(USBD_EP_RLZED, USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_realize_hwep()
845 udc->realized_eps &= ~(1 << hwep); in udc_unrealize_hwep()
846 writel(udc->realized_eps, USBD_REEP(udc->udp_baseaddr)); in udc_unrealize_hwep()
868 /* Stalls the endpoint - endpoint will return STALL */
925 dd = dma_pool_alloc(udc->dd_cache, GFP_ATOMIC | GFP_DMA, &dma); in udc_dd_alloc()
927 dd->this_dma = dma; in udc_dd_alloc()
935 dma_pool_free(udc->dd_cache, dd, dd->this_dma); in udc_dd_free()
949 if (udc->clocked) in udc_clk_set()
952 udc->clocked = 1; in udc_clk_set()
953 clk_prepare_enable(udc->usb_slv_clk); in udc_clk_set()
955 if (!udc->clocked) in udc_clk_set()
958 udc->clocked = 0; in udc_clk_set()
959 clk_disable_unprepare(udc->usb_slv_clk); in udc_clk_set()
972 /* Setup up a IN request for DMA transfer - this consists of determining the
978 u32 hwep = ep->hwep_num; in udc_ep_in_req_dma()
980 ep->req_pending = 1; in udc_ep_in_req_dma()
983 req = list_entry(ep->queue.next, struct lpc32xx_request, queue); in udc_ep_in_req_dma()
986 udc->udca_v_base[hwep] = req->dd_desc_ptr->this_dma; in udc_ep_in_req_dma()
992 if (req->req.length % ep->ep.maxpacket) in udc_ep_in_req_dma()
993 req->send_zlp = 0; in udc_ep_in_req_dma()
998 /* Setup up a OUT request for DMA transfer - this consists of determining the
1004 u32 hwep = ep->hwep_num; in udc_ep_out_req_dma()
1006 ep->req_pending = 1; in udc_ep_out_req_dma()
1009 req = list_entry(ep->queue.next, struct lpc32xx_request, queue); in udc_ep_out_req_dma()
1012 udc->udca_v_base[hwep] = req->dd_desc_ptr->this_dma; in udc_ep_out_req_dma()
1036 udc->udca_v_base[i] = 0; in udc_disable()
1040 writel((1 << i), USBD_EOTINTCLR(udc->udp_baseaddr)); in udc_disable()
1041 writel((1 << i), USBD_NDDRTINTCLR(udc->udp_baseaddr)); in udc_disable()
1042 writel((1 << i), USBD_SYSERRTINTCLR(udc->udp_baseaddr)); in udc_disable()
1043 writel((1 << i), USBD_DMARCLR(udc->udp_baseaddr)); in udc_disable()
1047 writel(0, USBD_DMAINTEN(udc->udp_baseaddr)); in udc_disable()
1049 writel(0, USBD_UDCAH(udc->udp_baseaddr)); in udc_disable()
1055 struct lpc32xx_ep *ep = &udc->ep[0]; in udc_enable()
1064 writel(USBD_EP_FAST, USBD_DEVINTPRI(udc->udp_baseaddr)); in udc_enable()
1065 writel(0xFFFF, USBD_EPINTPRI(udc->udp_baseaddr)); in udc_enable()
1068 writel(0x3FF, USBD_DEVINTCLR(udc->udp_baseaddr)); in udc_enable()
1070 /* Setup UDCA - not yet used (DMA) */ in udc_enable()
1071 writel(udc->udca_p_base, USBD_UDCAH(udc->udp_baseaddr)); in udc_enable()
1075 udc_realize_hwep(udc, i, ep->ep.maxpacket); in udc_enable()
1088 /* Set device address to 0 - called twice to force a latch in the USB in udc_enable()
1095 USBD_DMAINTEN(udc->udp_baseaddr)); in udc_enable()
1097 udc->dev_status = 0; in udc_enable()
1105 /* Connection change event - notify board function of change */
1109 if (udc->board->conn_chgb != NULL) in uda_power_event()
1110 udc->board->conn_chgb(conn); in uda_power_event()
1113 /* Suspend/resume event - notify board function of change */
1117 if (udc->board->susp_chgb != NULL) in uda_resm_susp_event()
1118 udc->board->susp_chgb(conn); in uda_resm_susp_event()
1121 udc->suspended = 0; in uda_resm_susp_event()
1123 udc->suspended = 1; in uda_resm_susp_event()
1126 /* Remote wakeup enable/disable - notify board function of change */
1129 if (udc->board->rmwk_chgb != NULL) in uda_remwkp_cgh()
1130 udc->board->rmwk_chgb(udc->dev_status & in uda_remwkp_cgh()
1143 case 0: /* 32-bit aligned */ in udc_pop_fifo()
1147 /* Copy 32-bit aligned data first */ in udc_pop_fifo()
1149 *p32++ = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1152 bl = bytes - cbytes; in udc_pop_fifo()
1154 tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1161 case 1: /* 8-bit aligned */ in udc_pop_fifo()
1165 tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1167 bl = bytes - n; in udc_pop_fifo()
1176 case 2: /* 16-bit aligned */ in udc_pop_fifo()
1180 /* Copy 32-bit sized objects first with 16-bit alignment */ in udc_pop_fifo()
1182 tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1188 bl = bytes - cbytes; in udc_pop_fifo()
1190 tmp = readl(USBD_RXDATA(udc->udp_baseaddr)); in udc_pop_fifo()
1210 writel(hwrep, USBD_CTRL(udc->udp_baseaddr)); in udc_read_hwep()
1213 while ((((tmpv = readl(USBD_RXPLEN(udc->udp_baseaddr))) & in udc_read_hwep()
1215 to--; in udc_read_hwep()
1217 dev_dbg(udc->dev, "No packet ready on FIFO EP read\n"); in udc_read_hwep()
1227 writel(((hwep & 0x1E) << 1), USBD_CTRL(udc->udp_baseaddr)); in udc_read_hwep()
1244 case 0: /* 32-bit aligned */ in udc_stuff_fifo()
1248 /* Copy 32-bit aligned data first */ in udc_stuff_fifo()
1250 writel(*p32++, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1253 bl = bytes - cbytes; in udc_stuff_fifo()
1259 writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1263 case 1: /* 8-bit aligned */ in udc_stuff_fifo()
1267 bl = bytes - n; in udc_stuff_fifo()
1275 writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1279 case 2: /* 16-bit aligned */ in udc_stuff_fifo()
1283 /* Copy 32-bit aligned data first */ in udc_stuff_fifo()
1287 writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1291 bl = bytes - cbytes; in udc_stuff_fifo()
1297 writel(tmp, USBD_TXDATA(udc->udp_baseaddr)); in udc_stuff_fifo()
1315 writel(hwwep, USBD_CTRL(udc->udp_baseaddr)); in udc_write_hwep()
1317 writel(bytes, USBD_TXPLEN(udc->udp_baseaddr)); in udc_write_hwep()
1321 writel(0, USBD_TXDATA(udc->udp_baseaddr)); in udc_write_hwep()
1325 writel(((hwep & 0x1E) << 1), USBD_CTRL(udc->udp_baseaddr)); in udc_write_hwep()
1330 /* USB device reset - resets USB to a default state with just EP0
1335 /* Re-init device controller and EP0 */ in uda_usb_reset()
1337 udc->gadget.speed = USB_SPEED_FULL; in uda_usb_reset()
1340 struct lpc32xx_ep *ep = &udc->ep[i]; in uda_usb_reset()
1341 ep->req_pending = 0; in uda_usb_reset()
1363 /* Set the device as configured - enables all endpoints */
1369 /* Set the device as unconfigured - disables all endpoints */
1380 INIT_LIST_HEAD(&udc->gadget.ep_list); in udc_reinit()
1381 INIT_LIST_HEAD(&udc->gadget.ep0->ep_list); in udc_reinit()
1384 struct lpc32xx_ep *ep = &udc->ep[i]; in udc_reinit()
1387 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in udc_reinit()
1388 usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); in udc_reinit()
1389 INIT_LIST_HEAD(&ep->queue); in udc_reinit()
1390 ep->req_pending = 0; in udc_reinit()
1393 udc->ep0state = WAIT_FOR_SETUP; in udc_reinit()
1399 struct lpc32xx_udc *udc = ep->udc; in done()
1401 list_del_init(&req->queue); in done()
1402 if (req->req.status == -EINPROGRESS) in done()
1403 req->req.status = status; in done()
1405 status = req->req.status; in done()
1407 if (ep->lep) { in done()
1408 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in); in done()
1411 udc_dd_free(udc, req->dd_desc_ptr); in done()
1414 if (status && status != -ESHUTDOWN) in done()
1415 ep_dbg(ep, "%s done %p, status %d\n", ep->ep.name, req, status); in done()
1417 ep->req_pending = 0; in done()
1418 spin_unlock(&udc->lock); in done()
1419 usb_gadget_giveback_request(&ep->ep, &req->req); in done()
1420 spin_lock(&udc->lock); in done()
1428 while (!list_empty(&ep->queue)) { in nuke()
1429 req = list_entry(ep->queue.next, struct lpc32xx_request, queue); in nuke()
1433 if (status == -ESHUTDOWN) { in nuke()
1434 uda_disable_hwepint(ep->udc, ep->hwep_num); in nuke()
1435 udc_disable_hwep(ep->udc, ep->hwep_num); in nuke()
1443 struct lpc32xx_ep *ep0 = &udc->ep[0]; in udc_ep0_in_req()
1446 if (list_empty(&ep0->queue)) in udc_ep0_in_req()
1450 req = list_entry(ep0->queue.next, struct lpc32xx_request, in udc_ep0_in_req()
1453 tsend = ts = req->req.length - req->req.actual; in udc_ep0_in_req()
1459 } else if (ts > ep0->ep.maxpacket) in udc_ep0_in_req()
1460 ts = ep0->ep.maxpacket; /* Just send what we can */ in udc_ep0_in_req()
1463 udc_write_hwep(udc, EP_IN, (req->req.buf + req->req.actual), ts); in udc_ep0_in_req()
1466 req->req.actual += ts; in udc_ep0_in_req()
1468 if (tsend >= ep0->ep.maxpacket) in udc_ep0_in_req()
1472 udc->ep0state = WAIT_FOR_SETUP; in udc_ep0_in_req()
1481 struct lpc32xx_ep *ep0 = &udc->ep[0]; in udc_ep0_out_req()
1484 if (list_empty(&ep0->queue)) in udc_ep0_out_req()
1487 req = list_entry(ep0->queue.next, struct lpc32xx_request, in udc_ep0_out_req()
1490 if (req->req.length == 0) { in udc_ep0_out_req()
1493 udc->ep0state = WAIT_FOR_SETUP; in udc_ep0_out_req()
1498 bufferspace = req->req.length - req->req.actual; in udc_ep0_out_req()
1499 if (bufferspace > ep0->ep.maxpacket) in udc_ep0_out_req()
1500 bufferspace = ep0->ep.maxpacket; in udc_ep0_out_req()
1503 prefetchw(req->req.buf + req->req.actual); in udc_ep0_out_req()
1504 tr = udc_read_hwep(udc, EP_OUT, req->req.buf + req->req.actual, in udc_ep0_out_req()
1506 req->req.actual += bufferspace; in udc_ep0_out_req()
1508 if (tr < ep0->ep.maxpacket) { in udc_ep0_out_req()
1511 udc->ep0state = WAIT_FOR_SETUP; in udc_ep0_out_req()
1521 struct usb_gadget_driver *driver = udc->driver; in stop_activity()
1524 if (udc->gadget.speed == USB_SPEED_UNKNOWN) in stop_activity()
1527 udc->gadget.speed = USB_SPEED_UNKNOWN; in stop_activity()
1528 udc->suspended = 0; in stop_activity()
1531 struct lpc32xx_ep *ep = &udc->ep[i]; in stop_activity()
1532 nuke(ep, -ESHUTDOWN); in stop_activity()
1535 spin_unlock(&udc->lock); in stop_activity()
1536 driver->disconnect(&udc->gadget); in stop_activity()
1537 spin_lock(&udc->lock); in stop_activity()
1551 if (!udc->clocked) in pullup()
1554 if (!udc->enabled || !udc->vbus) in pullup()
1557 if (is_on != udc->pullup) in pullup()
1565 struct lpc32xx_udc *udc = ep->udc; in lpc32xx_ep_disable()
1568 if ((ep->hwep_num_base == 0) || (ep->hwep_num == 0)) in lpc32xx_ep_disable()
1569 return -EINVAL; in lpc32xx_ep_disable()
1570 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_ep_disable()
1572 nuke(ep, -ESHUTDOWN); in lpc32xx_ep_disable()
1575 udc_ep_dma_disable(udc, ep->hwep_num); in lpc32xx_ep_disable()
1576 writel(1 << ep->hwep_num, USBD_EOTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_disable()
1577 writel(1 << ep->hwep_num, USBD_NDDRTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_disable()
1578 writel(1 << ep->hwep_num, USBD_SYSERRTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_disable()
1579 writel(1 << ep->hwep_num, USBD_DMARCLR(udc->udp_baseaddr)); in lpc32xx_ep_disable()
1582 udc->udca_v_base[ep->hwep_num] = 0; in lpc32xx_ep_disable()
1585 uda_clear_hwepint(udc, ep->hwep_num); in lpc32xx_ep_disable()
1586 udc_unrealize_hwep(udc, ep->hwep_num); in lpc32xx_ep_disable()
1588 ep->hwep_num = 0; in lpc32xx_ep_disable()
1590 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_ep_disable()
1592 atomic_dec(&udc->enabled_ep_cnt); in lpc32xx_ep_disable()
1593 wake_up(&udc->ep_disable_wait_queue); in lpc32xx_ep_disable()
1610 (desc->bDescriptorType != USB_DT_ENDPOINT)) in lpc32xx_ep_enable()
1611 return -EINVAL; in lpc32xx_ep_enable()
1613 udc = ep->udc; in lpc32xx_ep_enable()
1615 if ((maxpacket == 0) || (maxpacket > ep->maxpacket)) { in lpc32xx_ep_enable()
1616 dev_dbg(udc->dev, "bad ep descriptor's packet size\n"); in lpc32xx_ep_enable()
1617 return -EINVAL; in lpc32xx_ep_enable()
1621 if (ep->hwep_num_base == 0) { in lpc32xx_ep_enable()
1622 dev_dbg(udc->dev, "Can't re-enable EP0!!!\n"); in lpc32xx_ep_enable()
1623 return -EINVAL; in lpc32xx_ep_enable()
1627 if ((!udc->driver) || (udc->gadget.speed == USB_SPEED_UNKNOWN)) { in lpc32xx_ep_enable()
1628 dev_dbg(udc->dev, "bogus device state\n"); in lpc32xx_ep_enable()
1629 return -ESHUTDOWN; in lpc32xx_ep_enable()
1632 tmp = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; in lpc32xx_ep_enable()
1635 return -EINVAL; in lpc32xx_ep_enable()
1638 if (maxpacket > ep->maxpacket) { in lpc32xx_ep_enable()
1639 dev_dbg(udc->dev, in lpc32xx_ep_enable()
1641 return -EINVAL; in lpc32xx_ep_enable()
1654 dev_dbg(udc->dev, in lpc32xx_ep_enable()
1656 return -EINVAL; in lpc32xx_ep_enable()
1663 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_ep_enable()
1666 ep->is_in = (desc->bEndpointAddress & USB_DIR_IN) != 0; in lpc32xx_ep_enable()
1667 ep->ep.maxpacket = maxpacket; in lpc32xx_ep_enable()
1670 if (ep->is_in) in lpc32xx_ep_enable()
1672 ep->hwep_num = ep->hwep_num_base + EP_IN; in lpc32xx_ep_enable()
1674 ep->hwep_num = ep->hwep_num_base; in lpc32xx_ep_enable()
1676 ep_dbg(ep, "EP enabled: %s, HW:%d, MP:%d IN:%d\n", ep->ep.name, in lpc32xx_ep_enable()
1677 ep->hwep_num, maxpacket, (ep->is_in == 1)); in lpc32xx_ep_enable()
1681 udc_realize_hwep(udc, ep->hwep_num, ep->ep.maxpacket); in lpc32xx_ep_enable()
1682 udc_clr_buffer_hwep(udc, ep->hwep_num); in lpc32xx_ep_enable()
1683 uda_disable_hwepint(udc, ep->hwep_num); in lpc32xx_ep_enable()
1684 udc_clrstall_hwep(udc, ep->hwep_num); in lpc32xx_ep_enable()
1687 udc_ep_dma_disable(udc, ep->hwep_num); in lpc32xx_ep_enable()
1688 writel(1 << ep->hwep_num, USBD_EOTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_enable()
1689 writel(1 << ep->hwep_num, USBD_NDDRTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_enable()
1690 writel(1 << ep->hwep_num, USBD_SYSERRTINTCLR(udc->udp_baseaddr)); in lpc32xx_ep_enable()
1691 writel(1 << ep->hwep_num, USBD_DMARCLR(udc->udp_baseaddr)); in lpc32xx_ep_enable()
1693 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_ep_enable()
1695 atomic_inc(&udc->enabled_ep_cnt); in lpc32xx_ep_enable()
1712 INIT_LIST_HEAD(&req->queue); in lpc32xx_ep_alloc_request()
1713 return &req->req; in lpc32xx_ep_alloc_request()
1717 * De-allocate a USB request list
1726 BUG_ON(!list_empty(&req->queue)); in lpc32xx_ep_free_request()
1743 if (!_ep || !_req || !_req->complete || !_req->buf || in lpc32xx_ep_queue()
1744 !list_empty(&req->queue)) in lpc32xx_ep_queue()
1745 return -EINVAL; in lpc32xx_ep_queue()
1747 udc = ep->udc; in lpc32xx_ep_queue()
1749 if (udc->gadget.speed == USB_SPEED_UNKNOWN) in lpc32xx_ep_queue()
1750 return -EPIPE; in lpc32xx_ep_queue()
1752 if (ep->lep) { in lpc32xx_ep_queue()
1755 status = usb_gadget_map_request(&udc->gadget, _req, ep->is_in); in lpc32xx_ep_queue()
1763 return -ENOMEM; in lpc32xx_ep_queue()
1765 req->dd_desc_ptr = dd; in lpc32xx_ep_queue()
1768 dd->dd_next_phy = dd->dd_next_v = 0; in lpc32xx_ep_queue()
1769 dd->dd_buffer_addr = req->req.dma; in lpc32xx_ep_queue()
1770 dd->dd_status = 0; in lpc32xx_ep_queue()
1773 if (ep->eptype == EP_ISO_TYPE) { in lpc32xx_ep_queue()
1774 dd->dd_setup = DD_SETUP_ISO_EP | in lpc32xx_ep_queue()
1777 dd->dd_iso_ps_mem_addr = dd->this_dma + 24; in lpc32xx_ep_queue()
1778 if (ep->is_in) in lpc32xx_ep_queue()
1779 dd->iso_status[0] = req->req.length; in lpc32xx_ep_queue()
1781 dd->iso_status[0] = 0; in lpc32xx_ep_queue()
1783 dd->dd_setup = DD_SETUP_PACKETLEN(ep->ep.maxpacket) | in lpc32xx_ep_queue()
1784 DD_SETUP_DMALENBYTES(req->req.length); in lpc32xx_ep_queue()
1787 ep_dbg(ep, "%s queue req %p len %d buf %p (in=%d) z=%d\n", _ep->name, in lpc32xx_ep_queue()
1788 _req, _req->length, _req->buf, ep->is_in, _req->zero); in lpc32xx_ep_queue()
1790 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_ep_queue()
1792 _req->status = -EINPROGRESS; in lpc32xx_ep_queue()
1793 _req->actual = 0; in lpc32xx_ep_queue()
1794 req->send_zlp = _req->zero; in lpc32xx_ep_queue()
1797 if (list_empty(&ep->queue)) { in lpc32xx_ep_queue()
1798 list_add_tail(&req->queue, &ep->queue); in lpc32xx_ep_queue()
1800 if (ep->hwep_num_base == 0) { in lpc32xx_ep_queue()
1802 if (ep->is_in) { in lpc32xx_ep_queue()
1804 udc->ep0state = DATA_IN; in lpc32xx_ep_queue()
1808 udc->ep0state = DATA_OUT; in lpc32xx_ep_queue()
1811 } else if (ep->is_in) { in lpc32xx_ep_queue()
1813 if (!ep->req_pending) in lpc32xx_ep_queue()
1817 if (!ep->req_pending) in lpc32xx_ep_queue()
1820 list_add_tail(&req->queue, &ep->queue); in lpc32xx_ep_queue()
1822 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_ep_queue()
1835 if (!_ep || ep->hwep_num_base == 0) in lpc32xx_ep_dequeue()
1836 return -EINVAL; in lpc32xx_ep_dequeue()
1838 spin_lock_irqsave(&ep->udc->lock, flags); in lpc32xx_ep_dequeue()
1841 list_for_each_entry(iter, &ep->queue, queue) { in lpc32xx_ep_dequeue()
1842 if (&iter->req != _req) in lpc32xx_ep_dequeue()
1848 spin_unlock_irqrestore(&ep->udc->lock, flags); in lpc32xx_ep_dequeue()
1849 return -EINVAL; in lpc32xx_ep_dequeue()
1852 done(ep, req, -ECONNRESET); in lpc32xx_ep_dequeue()
1854 spin_unlock_irqrestore(&ep->udc->lock, flags); in lpc32xx_ep_dequeue()
1866 if ((!ep) || (ep->hwep_num <= 1)) in lpc32xx_ep_set_halt()
1867 return -EINVAL; in lpc32xx_ep_set_halt()
1870 if (ep->is_in) in lpc32xx_ep_set_halt()
1871 return -EAGAIN; in lpc32xx_ep_set_halt()
1873 udc = ep->udc; in lpc32xx_ep_set_halt()
1874 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_ep_set_halt()
1878 udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(ep->hwep_num), in lpc32xx_ep_set_halt()
1882 ep->wedge = 0; in lpc32xx_ep_set_halt()
1883 udc_protocol_cmd_data_w(udc, CMD_SET_EP_STAT(ep->hwep_num), in lpc32xx_ep_set_halt()
1887 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_ep_set_halt()
1897 if (!_ep || !ep->udc) in lpc32xx_ep_set_wedge()
1898 return -EINVAL; in lpc32xx_ep_set_wedge()
1900 ep->wedge = 1; in lpc32xx_ep_set_wedge()
1916 /* Send a ZLP on a non-0 IN EP */
1920 udc_clearep_getsts(udc, ep->hwep_num); in udc_send_in_zlp()
1923 udc_write_hwep(udc, ep->hwep_num, NULL, 0); in udc_send_in_zlp()
1936 if (ep->hwep_num <= 0) in udc_handle_eps()
1939 uda_clear_hwepint(udc, ep->hwep_num); in udc_handle_eps()
1942 if (!(udc->enabled_hwepints & (1 << ep->hwep_num))) in udc_handle_eps()
1946 epstatus = udc_clearep_getsts(udc, ep->hwep_num); in udc_handle_eps()
1955 if (ep->is_in) { in udc_handle_eps()
1957 uda_disable_hwepint(udc, ep->hwep_num); in udc_handle_eps()
1962 req = list_entry(ep->queue.next, struct lpc32xx_request, queue); in udc_handle_eps()
1967 if (!list_empty(&ep->queue)) { in udc_handle_eps()
1968 if (ep->is_in) in udc_handle_eps()
1973 ep->req_pending = 0; in udc_handle_eps()
1985 ep->totalints++; in udc_handle_dma_ep()
1988 req = list_entry(ep->queue.next, struct lpc32xx_request, queue); in udc_handle_dma_ep()
1989 dd = req->dd_desc_ptr; in udc_handle_dma_ep()
1992 if (!(dd->dd_status & DD_STATUS_DD_RETIRED)) in udc_handle_dma_ep()
1996 udc_ep_dma_disable(udc, ep->hwep_num); in udc_handle_dma_ep()
1997 writel((1 << ep->hwep_num), USBD_EOTINTCLR(udc->udp_baseaddr)); in udc_handle_dma_ep()
1998 writel((1 << ep->hwep_num), USBD_NDDRTINTCLR(udc->udp_baseaddr)); in udc_handle_dma_ep()
2001 if (readl(USBD_SYSERRTINTST(udc->udp_baseaddr)) & in udc_handle_dma_ep()
2002 (1 << ep->hwep_num)) { in udc_handle_dma_ep()
2003 writel((1 << ep->hwep_num), in udc_handle_dma_ep()
2004 USBD_SYSERRTINTCLR(udc->udp_baseaddr)); in udc_handle_dma_ep()
2006 ep->req_pending = 0; in udc_handle_dma_ep()
2011 done(ep, req, -ECONNABORTED); in udc_handle_dma_ep()
2016 status = dd->dd_status; in udc_handle_dma_ep()
2020 ep->req_pending = 0; in udc_handle_dma_ep()
2024 done(ep, req, -ECONNABORTED); in udc_handle_dma_ep()
2028 /* Interrupt only fires on EOT - This shouldn't happen! */ in udc_handle_dma_ep()
2029 ep->req_pending = 0; in udc_handle_dma_ep()
2032 done(ep, req, -ECONNABORTED); in udc_handle_dma_ep()
2043 ep->req_pending = 0; in udc_handle_dma_ep()
2046 done(ep, req, -ECONNABORTED); in udc_handle_dma_ep()
2051 if (ep->eptype == EP_ISO_TYPE) { in udc_handle_dma_ep()
2052 if (ep->is_in) in udc_handle_dma_ep()
2053 req->req.actual = req->req.length; in udc_handle_dma_ep()
2055 req->req.actual = dd->iso_status[0] & 0xFFFF; in udc_handle_dma_ep()
2057 req->req.actual += DD_STATUS_CURDMACNT(status); in udc_handle_dma_ep()
2059 /* Send a ZLP if necessary. This will be done for non-int in udc_handle_dma_ep()
2061 if (req->send_zlp) { in udc_handle_dma_ep()
2067 if (udc_clearep_getsts(udc, ep->hwep_num) & EP_SEL_F) { in udc_handle_dma_ep()
2068 udc_clearep_getsts(udc, ep->hwep_num); in udc_handle_dma_ep()
2069 uda_enable_hwepint(udc, ep->hwep_num); in udc_handle_dma_ep()
2070 udc_clearep_getsts(udc, ep->hwep_num); in udc_handle_dma_ep()
2082 udc_clearep_getsts(udc, ep->hwep_num); in udc_handle_dma_ep()
2083 if (!list_empty((&ep->queue))) { in udc_handle_dma_ep()
2084 if (ep->is_in) in udc_handle_dma_ep()
2089 ep->req_pending = 0; in udc_handle_dma_ep()
2111 if (udc->vbus == 0) in udc_handle_dev()
2113 else if ((udc->gadget.speed != USB_SPEED_UNKNOWN) && in udc_handle_dev()
2114 udc->driver) { in udc_handle_dev()
2116 udc->poweron = 0; in udc_handle_dev()
2117 schedule_work(&udc->pullup_job); in udc_handle_dev()
2120 } else if ((udc->gadget.speed != USB_SPEED_UNKNOWN) && in udc_handle_dev()
2121 udc->driver && udc->vbus) { in udc_handle_dev()
2124 udc->poweron = 1; in udc_handle_dev()
2125 schedule_work(&udc->pullup_job); in udc_handle_dev()
2140 ep0buff = udc->gadget.is_selfpowered; in udc_get_status()
2141 if (udc->dev_status & (1 << USB_DEVICE_REMOTE_WAKEUP)) in udc_get_status()
2147 ep = &udc->ep[tmp]; in udc_get_status()
2149 return -EOPNOTSUPP; in udc_get_status()
2152 if (!ep->is_in) in udc_get_status()
2153 return -EOPNOTSUPP; /* Something's wrong */ in udc_get_status()
2154 } else if (ep->is_in) in udc_get_status()
2155 return -EOPNOTSUPP; /* Not an IN endpoint */ in udc_get_status()
2158 udc_protocol_cmd_w(udc, CMD_SEL_EP(ep->hwep_num)); in udc_get_status()
2159 tmp = udc_protocol_cmd_r(udc, DAT_SEL_EP(ep->hwep_num)); in udc_get_status()
2179 struct lpc32xx_ep *ep, *ep0 = &udc->ep[0]; in udc_handle_ep0_setup()
2185 nuke(ep0, -EPROTO); in udc_handle_ep0_setup()
2202 ep0->is_in = 1; in udc_handle_ep0_setup()
2204 ep0->is_in = 0; in udc_handle_ep0_setup()
2218 udc->dev_status &= in udc_handle_ep0_setup()
2221 udc->dev_status |= in udc_handle_ep0_setup()
2233 ep = &udc->ep[tmp]; in udc_handle_ep0_setup()
2234 tmp = ep->hwep_num; in udc_handle_ep0_setup()
2240 else if (!ep->wedge) in udc_handle_ep0_setup()
2265 if (likely(udc->driver)) { in udc_handle_ep0_setup()
2266 /* device-2-host (IN) or no data setup command, process in udc_handle_ep0_setup()
2268 spin_unlock(&udc->lock); in udc_handle_ep0_setup()
2269 i = udc->driver->setup(&udc->gadget, &ctrlpkt); in udc_handle_ep0_setup()
2271 spin_lock(&udc->lock); in udc_handle_ep0_setup()
2293 dev_dbg(udc->dev, in udc_handle_ep0_setup()
2296 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_setup()
2301 if (!ep0->is_in) in udc_handle_ep0_setup()
2318 struct lpc32xx_ep *ep0 = &udc->ep[0]; in udc_handle_ep0_in()
2325 ep0->totalints++; in udc_handle_ep0_in()
2331 nuke(ep0, -ECONNABORTED); in udc_handle_ep0_in()
2332 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_in()
2339 if (udc->ep0state == DATA_IN) in udc_handle_ep0_in()
2342 /* Unknown state for EP0 oe end of DATA IN phase */ in udc_handle_ep0_in()
2343 nuke(ep0, -ECONNABORTED); in udc_handle_ep0_in()
2344 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_in()
2352 struct lpc32xx_ep *ep0 = &udc->ep[0]; in udc_handle_ep0_out()
2360 ep0->totalints++; in udc_handle_ep0_out()
2366 nuke(ep0, -ECONNABORTED); in udc_handle_ep0_out()
2367 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_out()
2377 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_out()
2383 switch (udc->ep0state) { in udc_handle_ep0_out()
2394 nuke(ep0, -ECONNABORTED); in udc_handle_ep0_out()
2395 udc->ep0state = WAIT_FOR_SETUP; in udc_handle_ep0_out()
2406 if (!udc->clocked) in lpc32xx_get_frame()
2407 return -EINVAL; in lpc32xx_get_frame()
2409 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_get_frame()
2413 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_get_frame()
2420 return -ENOTSUPP; in lpc32xx_wakeup()
2425 gadget->is_selfpowered = (is_on != 0); in lpc32xx_set_selfpowered()
2439 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_vbus_session()
2442 if (udc->driver) { in lpc32xx_vbus_session()
2450 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_vbus_session()
2456 if (atomic_read(&udc->enabled_ep_cnt)) in lpc32xx_vbus_session()
2457 wait_event_interruptible(udc->ep_disable_wait_queue, in lpc32xx_vbus_session()
2458 (atomic_read(&udc->enabled_ep_cnt) == 0)); in lpc32xx_vbus_session()
2460 spin_lock_irqsave(&udc->lock, flags); in lpc32xx_vbus_session()
2465 spin_unlock_irqrestore(&udc->lock, flags); in lpc32xx_vbus_session()
2523 .name = "ep1-int",
2536 .name = "ep2-bulk",
2549 .name = "ep3-iso",
2562 .name = "ep4-int",
2575 .name = "ep5-bulk",
2588 .name = "ep6-iso",
2601 .name = "ep7-int",
2614 .name = "ep8-bulk",
2627 .name = "ep9-iso",
2640 .name = "ep10-int",
2653 .name = "ep11-bulk",
2666 .name = "ep12-iso",
2679 .name = "ep13-int",
2692 .name = "ep14-bulk",
2705 .name = "ep15-bulk",
2724 spin_lock(&udc->lock); in lpc32xx_usb_lp_irq()
2727 devstat = readl(USBD_DEVINTST(udc->udp_baseaddr)); in lpc32xx_usb_lp_irq()
2730 writel(devstat, USBD_DEVINTCLR(udc->udp_baseaddr)); in lpc32xx_usb_lp_irq()
2731 devstat = devstat & udc->enabled_devints; in lpc32xx_usb_lp_irq()
2749 dev_dbg(udc->dev, "Device error (0x%x)!\n", tmp); in lpc32xx_usb_lp_irq()
2752 spin_unlock(&udc->lock); in lpc32xx_usb_lp_irq()
2763 spin_lock(&udc->lock); in lpc32xx_usb_hp_irq()
2766 writel(USBD_EP_FAST, USBD_DEVINTCLR(udc->udp_baseaddr)); in lpc32xx_usb_hp_irq()
2769 tmp = readl(USBD_EPINTST(udc->udp_baseaddr)); in lpc32xx_usb_hp_irq()
2788 if (tmp & (1 << udc->ep[i].hwep_num)) in lpc32xx_usb_hp_irq()
2789 udc_handle_eps(udc, &udc->ep[i]); in lpc32xx_usb_hp_irq()
2793 spin_unlock(&udc->lock); in lpc32xx_usb_hp_irq()
2805 spin_lock(&udc->lock); in lpc32xx_usb_devdma_irq()
2808 tmp = readl(USBD_EOTINTST(udc->udp_baseaddr)) | in lpc32xx_usb_devdma_irq()
2809 (readl(USBD_EPDMAST(udc->udp_baseaddr)) & in lpc32xx_usb_devdma_irq()
2810 readl(USBD_NDDRTINTST(udc->udp_baseaddr))) | in lpc32xx_usb_devdma_irq()
2811 readl(USBD_SYSERRTINTST(udc->udp_baseaddr)); in lpc32xx_usb_devdma_irq()
2813 if (tmp & (1 << udc->ep[i].hwep_num)) in lpc32xx_usb_devdma_irq()
2814 udc_handle_dma_ep(udc, &udc->ep[i]); in lpc32xx_usb_devdma_irq()
2817 spin_unlock(&udc->lock); in lpc32xx_usb_devdma_irq()
2831 if (udc->enabled != 0) { in vbus_work()
2833 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in vbus_work()
2840 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in vbus_work()
2845 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in vbus_work()
2850 value = i2c_smbus_read_byte_data(udc->isp1301_i2c_client, in vbus_work()
2855 udc->vbus = 1; in vbus_work()
2857 udc->vbus = 0; in vbus_work()
2860 if (udc->last_vbus != udc->vbus) { in vbus_work()
2861 udc->last_vbus = udc->vbus; in vbus_work()
2862 lpc32xx_vbus_session(&udc->gadget, udc->vbus); in vbus_work()
2881 if (!driver || driver->max_speed < USB_SPEED_FULL || !driver->setup) { in lpc32xx_start()
2882 dev_err(udc->dev, "bad parameter.\n"); in lpc32xx_start()
2883 return -EINVAL; in lpc32xx_start()
2886 if (udc->driver) { in lpc32xx_start()
2887 dev_err(udc->dev, "UDC already has a gadget driver\n"); in lpc32xx_start()
2888 return -EBUSY; in lpc32xx_start()
2891 udc->driver = driver; in lpc32xx_start()
2892 udc->gadget.dev.of_node = udc->dev->of_node; in lpc32xx_start()
2893 udc->enabled = 1; in lpc32xx_start()
2894 udc->gadget.is_selfpowered = 1; in lpc32xx_start()
2895 udc->vbus = 0; in lpc32xx_start()
2898 udc->last_vbus = udc->vbus = 0; in lpc32xx_start()
2902 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in lpc32xx_start()
2904 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in lpc32xx_start()
2914 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in lpc32xx_stop()
2916 i2c_smbus_write_byte_data(udc->isp1301_i2c_client, in lpc32xx_stop()
2919 if (udc->clocked) { in lpc32xx_stop()
2920 spin_lock(&udc->lock); in lpc32xx_stop()
2922 spin_unlock(&udc->lock); in lpc32xx_stop()
2929 if (atomic_read(&udc->enabled_ep_cnt)) in lpc32xx_stop()
2930 wait_event_interruptible(udc->ep_disable_wait_queue, in lpc32xx_stop()
2931 (atomic_read(&udc->enabled_ep_cnt) == 0)); in lpc32xx_stop()
2933 spin_lock(&udc->lock); in lpc32xx_stop()
2935 spin_unlock(&udc->lock); in lpc32xx_stop()
2938 udc->enabled = 0; in lpc32xx_stop()
2939 udc->driver = NULL; in lpc32xx_stop()
2984 struct device *dev = &pdev->dev; in lpc32xx_udc_probe()
2992 return -ENOMEM; in lpc32xx_udc_probe()
2995 udc->ep[i].udc = udc; in lpc32xx_udc_probe()
2996 udc->gadget.ep0 = &udc->ep[0].ep; in lpc32xx_udc_probe()
2999 udc->gadget.dev.parent = dev; in lpc32xx_udc_probe()
3000 udc->pdev = pdev; in lpc32xx_udc_probe()
3001 udc->dev = &pdev->dev; in lpc32xx_udc_probe()
3002 udc->enabled = 0; in lpc32xx_udc_probe()
3004 if (pdev->dev.of_node) { in lpc32xx_udc_probe()
3005 isp1301_node = of_parse_phandle(pdev->dev.of_node, in lpc32xx_udc_probe()
3011 udc->isp1301_i2c_client = isp1301_get_client(isp1301_node); in lpc32xx_udc_probe()
3013 if (!udc->isp1301_i2c_client) { in lpc32xx_udc_probe()
3014 return -EPROBE_DEFER; in lpc32xx_udc_probe()
3017 dev_info(udc->dev, "ISP1301 I2C device at address 0x%x\n", in lpc32xx_udc_probe()
3018 udc->isp1301_i2c_client->addr); in lpc32xx_udc_probe()
3020 pdev->dev.dma_mask = &lpc32xx_usbd_dmamask; in lpc32xx_udc_probe()
3021 retval = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); in lpc32xx_udc_probe()
3025 udc->board = &lpc32xx_usbddata; in lpc32xx_udc_probe()
3036 spin_lock_init(&udc->lock); in lpc32xx_udc_probe()
3040 udc->udp_irq[i] = platform_get_irq(pdev, i); in lpc32xx_udc_probe()
3041 if (udc->udp_irq[i] < 0) in lpc32xx_udc_probe()
3042 return udc->udp_irq[i]; in lpc32xx_udc_probe()
3045 udc->udp_baseaddr = devm_platform_ioremap_resource(pdev, 0); in lpc32xx_udc_probe()
3046 if (IS_ERR(udc->udp_baseaddr)) { in lpc32xx_udc_probe()
3047 dev_err(udc->dev, "IO map failure\n"); in lpc32xx_udc_probe()
3048 return PTR_ERR(udc->udp_baseaddr); in lpc32xx_udc_probe()
3052 udc->usb_slv_clk = devm_clk_get(&pdev->dev, NULL); in lpc32xx_udc_probe()
3053 if (IS_ERR(udc->usb_slv_clk)) { in lpc32xx_udc_probe()
3054 dev_err(udc->dev, "failed to acquire USB device clock\n"); in lpc32xx_udc_probe()
3055 return PTR_ERR(udc->usb_slv_clk); in lpc32xx_udc_probe()
3059 retval = clk_prepare_enable(udc->usb_slv_clk); in lpc32xx_udc_probe()
3061 dev_err(udc->dev, "failed to start USB device clock\n"); in lpc32xx_udc_probe()
3066 udc->poweron = udc->pullup = 0; in lpc32xx_udc_probe()
3067 INIT_WORK(&udc->pullup_job, pullup_work); in lpc32xx_udc_probe()
3069 INIT_WORK(&udc->power_job, power_work); in lpc32xx_udc_probe()
3073 udc->clocked = 1; in lpc32xx_udc_probe()
3077 udc->udca_v_base = dma_alloc_coherent(&pdev->dev, UDCA_BUFF_SIZE, in lpc32xx_udc_probe()
3080 if (!udc->udca_v_base) { in lpc32xx_udc_probe()
3081 dev_err(udc->dev, "error getting UDCA region\n"); in lpc32xx_udc_probe()
3082 retval = -ENOMEM; in lpc32xx_udc_probe()
3085 udc->udca_p_base = dma_handle; in lpc32xx_udc_probe()
3086 dev_dbg(udc->dev, "DMA buffer(0x%x bytes), P:0x%08x, V:0x%p\n", in lpc32xx_udc_probe()
3087 UDCA_BUFF_SIZE, udc->udca_p_base, udc->udca_v_base); in lpc32xx_udc_probe()
3090 udc->dd_cache = dma_pool_create("udc_dd", udc->dev, in lpc32xx_udc_probe()
3093 if (!udc->dd_cache) { in lpc32xx_udc_probe()
3094 dev_err(udc->dev, "error getting DD DMA region\n"); in lpc32xx_udc_probe()
3095 retval = -ENOMEM; in lpc32xx_udc_probe()
3103 /* Request IRQs - low and high priority USB device IRQs are routed to in lpc32xx_udc_probe()
3105 retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_LP], in lpc32xx_udc_probe()
3108 dev_err(udc->dev, "LP request irq %d failed\n", in lpc32xx_udc_probe()
3109 udc->udp_irq[IRQ_USB_LP]); in lpc32xx_udc_probe()
3112 retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_HP], in lpc32xx_udc_probe()
3115 dev_err(udc->dev, "HP request irq %d failed\n", in lpc32xx_udc_probe()
3116 udc->udp_irq[IRQ_USB_HP]); in lpc32xx_udc_probe()
3120 retval = devm_request_irq(dev, udc->udp_irq[IRQ_USB_DEVDMA], in lpc32xx_udc_probe()
3123 dev_err(udc->dev, "DEV request irq %d failed\n", in lpc32xx_udc_probe()
3124 udc->udp_irq[IRQ_USB_DEVDMA]); in lpc32xx_udc_probe()
3130 retval = devm_request_threaded_irq(dev, udc->udp_irq[IRQ_USB_ATX], NULL, in lpc32xx_udc_probe()
3134 dev_err(udc->dev, "VBUS request irq %d failed\n", in lpc32xx_udc_probe()
3135 udc->udp_irq[IRQ_USB_ATX]); in lpc32xx_udc_probe()
3140 init_waitqueue_head(&udc->ep_disable_wait_queue); in lpc32xx_udc_probe()
3141 atomic_set(&udc->enabled_ep_cnt, 0); in lpc32xx_udc_probe()
3143 retval = usb_add_gadget_udc(dev, &udc->gadget); in lpc32xx_udc_probe()
3154 dev_info(udc->dev, "%s version %s\n", driver_name, DRIVER_VERSION); in lpc32xx_udc_probe()
3159 dma_pool_destroy(udc->dd_cache); in lpc32xx_udc_probe()
3161 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, in lpc32xx_udc_probe()
3162 udc->udca_v_base, udc->udca_p_base); in lpc32xx_udc_probe()
3164 clk_disable_unprepare(udc->usb_slv_clk); in lpc32xx_udc_probe()
3165 dev_err(udc->dev, "%s probe failed, %d\n", driver_name, retval); in lpc32xx_udc_probe()
3174 usb_del_gadget_udc(&udc->gadget); in lpc32xx_udc_remove()
3175 if (udc->driver) { in lpc32xx_udc_remove()
3176 dev_err(&pdev->dev, in lpc32xx_udc_remove()
3185 device_init_wakeup(&pdev->dev, 0); in lpc32xx_udc_remove()
3188 dma_pool_destroy(udc->dd_cache); in lpc32xx_udc_remove()
3189 dma_free_coherent(&pdev->dev, UDCA_BUFF_SIZE, in lpc32xx_udc_remove()
3190 udc->udca_v_base, udc->udca_p_base); in lpc32xx_udc_remove()
3192 clk_disable_unprepare(udc->usb_slv_clk); in lpc32xx_udc_remove()
3200 if (udc->clocked) { in lpc32xx_udc_suspend()
3202 udc->poweron = 0; in lpc32xx_udc_suspend()
3208 /* Keep clock flag on, so we know to re-enable clocks in lpc32xx_udc_suspend()
3210 udc->clocked = 1; in lpc32xx_udc_suspend()
3213 clk_disable_unprepare(udc->usb_slv_clk); in lpc32xx_udc_suspend()
3223 if (udc->clocked) { in lpc32xx_udc_resume()
3225 clk_prepare_enable(udc->usb_slv_clk); in lpc32xx_udc_resume()
3231 udc->poweron = 1; in lpc32xx_udc_resume()
3244 { .compatible = "nxp,lpc3220-udc", },