Lines Matching refs:pdev

74 static int cdns2_get_dma_pos(struct cdns2_device *pdev,  in cdns2_get_dma_pos()  argument
79 dma_index = readl(&pdev->adma_regs->ep_traddr) - pep->ring.dma; in cdns2_get_dma_pos()
90 void cdns2_select_ep(struct cdns2_device *pdev, u32 ep) in cdns2_select_ep() argument
92 if (pdev->selected_ep == ep) in cdns2_select_ep()
95 pdev->selected_ep = ep; in cdns2_select_ep()
96 writel(ep, &pdev->adma_regs->ep_sel); in cdns2_select_ep()
109 struct cdns2_device *pdev = pep->pdev; in cdns2_free_tr_segment() local
113 dma_pool_free(pdev->eps_dma_pool, ring->trbs, ring->dma); in cdns2_free_tr_segment()
121 struct cdns2_device *pdev = pep->pdev; in cdns2_alloc_tr_segment() local
128 ring->trbs = dma_pool_alloc(pdev->eps_dma_pool, in cdns2_alloc_tr_segment()
155 struct cdns2_device *pdev = pep->pdev; in cdns2_ep_stall_flush() local
160 writel(DMA_EP_CMD_DFLUSH, &pdev->adma_regs->ep_cmd); in cdns2_ep_stall_flush()
163 readl_poll_timeout_atomic(&pdev->adma_regs->ep_cmd, val, in cdns2_ep_stall_flush()
205 static void cdns2_enable_l1(struct cdns2_device *pdev, int enable) in cdns2_enable_l1() argument
208 clear_reg_bit_8(&pdev->usb_regs->usbcs, USBCS_LPMNYET); in cdns2_enable_l1()
209 writeb(LPMCLOCK_SLEEP_ENTRY, &pdev->usb_regs->lpmclock); in cdns2_enable_l1()
211 set_reg_bit_8(&pdev->usb_regs->usbcs, USBCS_LPMNYET); in cdns2_enable_l1()
215 static enum usb_device_speed cdns2_get_speed(struct cdns2_device *pdev) in cdns2_get_speed() argument
217 u8 speed = readb(&pdev->usb_regs->speedctrl); in cdns2_get_speed()
241 struct cdns2_device *pdev = pep->pdev; in cdns2_gadget_giveback() local
248 usb_gadget_unmap_request_by_dev(pdev->dev, request, pep->dir); in cdns2_gadget_giveback()
256 spin_unlock(&pdev->lock); in cdns2_gadget_giveback()
258 spin_lock(&pdev->lock); in cdns2_gadget_giveback()
261 if (request->buf == pdev->zlp_buf) in cdns2_gadget_giveback()
283 struct cdns2_device *pdev = pep->pdev; in cdns2_wa1_update_guard() local
288 doorbell = !!(readl(&pdev->adma_regs->ep_cmd) & DMA_EP_CMD_DRDY); in cdns2_wa1_update_guard()
302 static void cdns2_wa1_tray_restore_cycle_bit(struct cdns2_device *pdev, in cdns2_wa1_tray_restore_cycle_bit() argument
308 doorbell = !!(readl(&pdev->adma_regs->ep_cmd) & DMA_EP_CMD_DRDY); in cdns2_wa1_tray_restore_cycle_bit()
309 dma_index = cdns2_get_dma_pos(pdev, pep); in cdns2_wa1_tray_restore_cycle_bit()
315 static int cdns2_prepare_ring(struct cdns2_device *pdev, in cdns2_prepare_ring() argument
333 doorbell = !!(readl(&pdev->adma_regs->ep_cmd) & DMA_EP_CMD_DRDY); in cdns2_prepare_ring()
334 dma_index = cdns2_get_dma_pos(pdev, pep); in cdns2_prepare_ring()
471 static void cdsn2_isoc_burst_opt(struct cdns2_device *pdev) in cdsn2_isoc_burst_opt() argument
492 pdev->burst_opt[i] = axi_burst_option[j]; in cdsn2_isoc_burst_opt()
584 TRB_BURST(pep->pdev->burst_opt[trb_buff_len]); in cdns2_ep_tx_isoc()
688 static void cdns2_set_drdy(struct cdns2_device *pdev, in cdns2_set_drdy() argument
700 &pdev->adma_regs->ep_sts); in cdns2_set_drdy()
701 writel(DMA_EP_CMD_DRDY, &pdev->adma_regs->ep_cmd); in cdns2_set_drdy()
703 if (readl(&pdev->adma_regs->ep_sts) & DMA_EP_STS_TRBERR) { in cdns2_set_drdy()
704 writel(DMA_EP_STS_TRBERR, &pdev->adma_regs->ep_sts); in cdns2_set_drdy()
705 writel(DMA_EP_CMD_DRDY, &pdev->adma_regs->ep_cmd); in cdns2_set_drdy()
708 trace_cdns2_doorbell_epx(pep, readl(&pdev->adma_regs->ep_traddr)); in cdns2_set_drdy()
711 static int cdns2_prepare_first_isoc_transfer(struct cdns2_device *pdev, in cdns2_prepare_first_isoc_transfer() argument
718 if ((readl(&pdev->adma_regs->ep_cmd) & DMA_EP_CMD_DRDY)) in cdns2_prepare_first_isoc_transfer()
722 set_reg_bit_32(&pdev->adma_regs->ep_cfg, DMA_EP_CFG_ENABLE); in cdns2_prepare_first_isoc_transfer()
724 &pdev->adma_regs->ep_traddr); in cdns2_prepare_first_isoc_transfer()
733 hw_ccs = !!DMA_EP_STS_CCS(readl(&pdev->adma_regs->ep_sts)); in cdns2_prepare_first_isoc_transfer()
753 set_reg_bit_32(&pdev->adma_regs->ep_cfg, DMA_EP_CFG_ENABLE); in cdns2_prepare_first_isoc_transfer()
755 &pdev->adma_regs->ep_traddr); in cdns2_prepare_first_isoc_transfer()
764 struct cdns2_device *pdev = pep->pdev; in cdns2_ep_run_transfer() local
770 cdns2_select_ep(pdev, pep->endpoint.address); in cdns2_ep_run_transfer()
778 ret = cdns2_prepare_ring(pdev, pep, num_trbs); in cdns2_ep_run_transfer()
804 cdns2_wa1_tray_restore_cycle_bit(pdev, pep); in cdns2_ep_run_transfer()
809 ret = cdns2_prepare_first_isoc_transfer(pdev, pep); in cdns2_ep_run_transfer()
814 cdns2_set_drdy(pdev, pep); in cdns2_ep_run_transfer()
821 static int cdns2_start_all_request(struct cdns2_device *pdev, in cdns2_start_all_request() argument
881 struct cdns2_device *pdev = pep->pdev; in cdns2_trb_handled() local
889 current_index = cdns2_get_dma_pos(pdev, pep); in cdns2_trb_handled()
890 doorbell = !!(readl(&pdev->adma_regs->ep_cmd) & DMA_EP_CMD_DRDY); in cdns2_trb_handled()
949 static void cdns2_skip_isoc_td(struct cdns2_device *pdev, in cdns2_skip_isoc_td() argument
966 cdns2_prepare_first_isoc_transfer(pdev, pep); in cdns2_skip_isoc_td()
968 cdns2_set_drdy(pdev, pep); in cdns2_skip_isoc_td()
971 static void cdns2_transfer_completed(struct cdns2_device *pdev, in cdns2_transfer_completed() argument
997 cdns2_select_ep(pdev, pep->endpoint.address); in cdns2_transfer_completed()
1035 cdns2_skip_isoc_td(pdev, pep, preq); in cdns2_transfer_completed()
1039 cdns2_start_all_request(pdev, pep); in cdns2_transfer_completed()
1042 static void cdns2_wakeup(struct cdns2_device *pdev) in cdns2_wakeup() argument
1044 if (!pdev->may_wakeup) in cdns2_wakeup()
1048 set_reg_bit_8(&pdev->usb_regs->usbcs, USBCS_SIGRSUME); in cdns2_wakeup()
1053 struct cdns2_device *pdev = pep->pdev; in cdns2_rearm_transfer() local
1063 writel(DMA_EP_CMD_DRDY, &pdev->adma_regs->ep_cmd); in cdns2_rearm_transfer()
1065 cdns2_wakeup(pdev); in cdns2_rearm_transfer()
1068 readl(&pdev->adma_regs->ep_traddr)); in cdns2_rearm_transfer()
1074 struct cdns2_device *pdev = pep->pdev; in cdns2_handle_epx_interrupt() local
1079 cdns2_select_ep(pdev, pep->endpoint.address); in cdns2_handle_epx_interrupt()
1081 trace_cdns2_epx_irq(pdev, pep); in cdns2_handle_epx_interrupt()
1083 ep_sts_reg = readl(&pdev->adma_regs->ep_sts); in cdns2_handle_epx_interrupt()
1084 writel(ep_sts_reg, &pdev->adma_regs->ep_sts); in cdns2_handle_epx_interrupt()
1091 cs = pep->dir ? readb(&pdev->epx_regs->ep[pep->num - 1].txcs) : in cdns2_handle_epx_interrupt()
1092 readb(&pdev->epx_regs->ep[pep->num - 1].rxcs); in cdns2_handle_epx_interrupt()
1103 clear_reg_bit_32(&pdev->adma_regs->ep_cfg, DMA_EP_CFG_ENABLE); in cdns2_handle_epx_interrupt()
1106 readl_poll_timeout_atomic(&pdev->adma_regs->ep_sts, val, in cdns2_handle_epx_interrupt()
1109 writel(DMA_EP_CMD_DFLUSH, &pep->pdev->adma_regs->ep_cmd); in cdns2_handle_epx_interrupt()
1112 readl_poll_timeout_atomic(&pep->pdev->adma_regs->ep_cmd, val, in cdns2_handle_epx_interrupt()
1132 clear_reg_bit_32(&pdev->adma_regs->ep_cfg, in cdns2_handle_epx_interrupt()
1135 cdns2_transfer_completed(pdev, pep); in cdns2_handle_epx_interrupt()
1138 cdns2_set_drdy(pdev, pep); in cdns2_handle_epx_interrupt()
1144 cdns2_transfer_completed(pdev, pep); in cdns2_handle_epx_interrupt()
1150 cdns2_start_all_request(pdev, pep); in cdns2_handle_epx_interrupt()
1160 cdns2_transfer_completed(pdev, pep); in cdns2_handle_epx_interrupt()
1163 static void cdns2_disconnect_gadget(struct cdns2_device *pdev) in cdns2_disconnect_gadget() argument
1165 if (pdev->gadget_driver && pdev->gadget_driver->disconnect) in cdns2_disconnect_gadget()
1166 pdev->gadget_driver->disconnect(&pdev->gadget); in cdns2_disconnect_gadget()
1171 struct cdns2_device *pdev = data; in cdns2_usb_irq_handler() local
1178 if (pdev->in_lpm) in cdns2_usb_irq_handler()
1181 reg_usb_irq_m = readb(&pdev->interrupt_regs->usbien); in cdns2_usb_irq_handler()
1182 reg_ext_irq_m = readb(&pdev->interrupt_regs->extien); in cdns2_usb_irq_handler()
1185 writeb(0, &pdev->interrupt_regs->usbien); in cdns2_usb_irq_handler()
1186 writeb(0, &pdev->interrupt_regs->extien); in cdns2_usb_irq_handler()
1187 writel(0, &pdev->adma_regs->ep_ien); in cdns2_usb_irq_handler()
1190 writel(0, &pdev->adma_regs->ep_sts); in cdns2_usb_irq_handler()
1191 writeb(0, &pdev->interrupt_regs->usbirq); in cdns2_usb_irq_handler()
1192 writeb(0, &pdev->interrupt_regs->extirq); in cdns2_usb_irq_handler()
1194 reg_ep_ists = readl(&pdev->adma_regs->ep_ists); in cdns2_usb_irq_handler()
1195 reg_usb_irq = readb(&pdev->interrupt_regs->usbirq); in cdns2_usb_irq_handler()
1196 reg_ext_irq = readb(&pdev->interrupt_regs->extirq); in cdns2_usb_irq_handler()
1202 writeb(USB_IEN_INIT, &pdev->interrupt_regs->usbien); in cdns2_usb_irq_handler()
1203 writeb(EXTIRQ_WAKEUP, &pdev->interrupt_regs->extien); in cdns2_usb_irq_handler()
1204 writel(~0, &pdev->adma_regs->ep_ien); in cdns2_usb_irq_handler()
1209 static irqreturn_t cdns2_thread_usb_irq_handler(struct cdns2_device *pdev) in cdns2_thread_usb_irq_handler() argument
1215 ext_irq = readb(&pdev->interrupt_regs->extirq) & EXTIRQ_WAKEUP; in cdns2_thread_usb_irq_handler()
1216 writeb(ext_irq, &pdev->interrupt_regs->extirq); in cdns2_thread_usb_irq_handler()
1218 usb_irq = readb(&pdev->interrupt_regs->usbirq) & USB_IEN_INIT; in cdns2_thread_usb_irq_handler()
1219 writeb(usb_irq, &pdev->interrupt_regs->usbirq); in cdns2_thread_usb_irq_handler()
1227 if (pdev->gadget_driver && pdev->gadget_driver->resume) { in cdns2_thread_usb_irq_handler()
1228 spin_unlock(&pdev->lock); in cdns2_thread_usb_irq_handler()
1229 pdev->gadget_driver->resume(&pdev->gadget); in cdns2_thread_usb_irq_handler()
1230 spin_lock(&pdev->lock); in cdns2_thread_usb_irq_handler()
1235 u8 reg = readb(&pdev->usb_regs->lpmctrl); in cdns2_thread_usb_irq_handler()
1239 writeb(0, &pdev->usb_regs->sleep_clkgate); in cdns2_thread_usb_irq_handler()
1243 if (pdev->gadget_driver && pdev->gadget_driver->suspend) { in cdns2_thread_usb_irq_handler()
1244 spin_unlock(&pdev->lock); in cdns2_thread_usb_irq_handler()
1245 pdev->gadget_driver->suspend(&pdev->gadget); in cdns2_thread_usb_irq_handler()
1246 spin_lock(&pdev->lock); in cdns2_thread_usb_irq_handler()
1251 if (pdev->gadget_driver) { in cdns2_thread_usb_irq_handler()
1252 pdev->dev_address = 0; in cdns2_thread_usb_irq_handler()
1254 spin_unlock(&pdev->lock); in cdns2_thread_usb_irq_handler()
1255 usb_gadget_udc_reset(&pdev->gadget, in cdns2_thread_usb_irq_handler()
1256 pdev->gadget_driver); in cdns2_thread_usb_irq_handler()
1257 spin_lock(&pdev->lock); in cdns2_thread_usb_irq_handler()
1267 speed = cdns2_get_speed(pdev); in cdns2_thread_usb_irq_handler()
1272 pdev->gadget.speed = speed; in cdns2_thread_usb_irq_handler()
1273 cdns2_enable_l1(pdev, 0); in cdns2_thread_usb_irq_handler()
1274 cdns2_ep0_config(pdev); in cdns2_thread_usb_irq_handler()
1275 pdev->may_wakeup = 0; in cdns2_thread_usb_irq_handler()
1280 pdev->ep0_stage = CDNS2_SETUP_STAGE; in cdns2_thread_usb_irq_handler()
1281 cdns2_handle_setup_packet(pdev); in cdns2_thread_usb_irq_handler()
1290 struct cdns2_device *pdev = data; in cdns2_thread_irq_handler() local
1296 spin_lock_irqsave(&pdev->lock, flags); in cdns2_thread_irq_handler()
1298 cdns2_thread_usb_irq_handler(pdev); in cdns2_thread_irq_handler()
1300 dma_ep_ists = readl(&pdev->adma_regs->ep_ists); in cdns2_thread_irq_handler()
1308 cdns2_handle_ep0_interrupt(pdev, USB_DIR_OUT); in cdns2_thread_irq_handler()
1312 cdns2_handle_ep0_interrupt(pdev, USB_DIR_IN); in cdns2_thread_irq_handler()
1325 cdns2_handle_epx_interrupt(&pdev->eps[ep_idx]); in cdns2_thread_irq_handler()
1329 writel(~0, &pdev->adma_regs->ep_ien); in cdns2_thread_irq_handler()
1330 writeb(USB_IEN_INIT, &pdev->interrupt_regs->usbien); in cdns2_thread_irq_handler()
1331 writeb(EXTIRQ_WAKEUP, &pdev->interrupt_regs->extien); in cdns2_thread_irq_handler()
1333 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_thread_irq_handler()
1340 static void cdns2_eps_onchip_buffer_init(struct cdns2_device *pdev) in cdns2_eps_onchip_buffer_init() argument
1351 pep = &pdev->eps[i]; in cdns2_eps_onchip_buffer_init()
1363 pep = &pdev->eps[i]; in cdns2_eps_onchip_buffer_init()
1369 free = pdev->onchip_tx_buf - min_buf_tx; in cdns2_eps_onchip_buffer_init()
1381 &pdev->epx_regs->txstaddr[pep->num - 1]); in cdns2_eps_onchip_buffer_init()
1382 pdev->epx_regs->txstaddr[pep->num - 1] = tx_offset; in cdns2_eps_onchip_buffer_init()
1384 dev_dbg(pdev->dev, "%s onchip address %04x, buffering: %d\n", in cdns2_eps_onchip_buffer_init()
1389 free = pdev->onchip_rx_buf - min_buf_rx; in cdns2_eps_onchip_buffer_init()
1400 &pdev->epx_regs->rxstaddr[pep->num - 1]); in cdns2_eps_onchip_buffer_init()
1402 dev_dbg(pdev->dev, "%s onchip address %04x, buffering: %d\n", in cdns2_eps_onchip_buffer_init()
1414 struct cdns2_device *pdev = pep->pdev; in cdns2_ep_config() local
1435 set_reg_bit_8(&pdev->epx_regs->isoautoarm, BIT(pep->num)); in cdns2_ep_config()
1436 set_reg_bit_8(&pdev->epx_regs->isoautodump, BIT(pep->num)); in cdns2_ep_config()
1437 set_reg_bit_8(&pdev->epx_regs->isodctrl, BIT(pep->num)); in cdns2_ep_config()
1441 switch (pdev->gadget.speed) { in cdns2_ep_config()
1457 writew(max_packet_size, &pdev->epx_regs->txmaxpack[pep->num - 1]); in cdns2_ep_config()
1458 writeb(ep_cfg, &pdev->epx_regs->ep[pep->num - 1].txcon); in cdns2_ep_config()
1460 writew(max_packet_size, &pdev->epx_regs->rxmaxpack[pep->num - 1]); in cdns2_ep_config()
1461 writeb(ep_cfg, &pdev->epx_regs->ep[pep->num - 1].rxcon); in cdns2_ep_config()
1465 &pdev->usb_regs->fifoctrl); in cdns2_ep_config()
1466 writeb(pep->num | dir, &pdev->epx_regs->endprst); in cdns2_ep_config()
1468 &pdev->epx_regs->endprst); in cdns2_ep_config()
1477 cdns2_select_ep(pdev, pep->num | pep->dir); in cdns2_ep_config()
1478 writel(DMA_EP_CMD_EPRST | DMA_EP_CMD_DFLUSH, &pdev->adma_regs->ep_cmd); in cdns2_ep_config()
1480 ret = readl_poll_timeout_atomic(&pdev->adma_regs->ep_cmd, val, in cdns2_ep_config()
1488 writel(DMA_EP_STS_TRBERR | DMA_EP_STS_ISOERR, &pdev->adma_regs->ep_sts_en); in cdns2_ep_config()
1491 writel(DMA_EP_CFG_ENABLE, &pdev->adma_regs->ep_cfg); in cdns2_ep_config()
1493 trace_cdns2_epx_hw_cfg(pdev, pep); in cdns2_ep_config()
1495 dev_dbg(pdev->dev, "Configure %s: with MPS: %08x, ep con: %02x\n", in cdns2_ep_config()
1532 struct cdns2_device *pdev; in cdns2_gadget_ep_enable() local
1543 pdev = pep->pdev; in cdns2_gadget_ep_enable()
1545 if (dev_WARN_ONCE(pdev->dev, pep->ep_state & EP_ENABLED, in cdns2_gadget_ep_enable()
1549 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_ep_enable()
1554 if (pdev->gadget.speed == USB_SPEED_FULL) in cdns2_gadget_ep_enable()
1560 dev_err(pdev->dev, "ISO period is limited to %d (current: %d)\n", in cdns2_gadget_ep_enable()
1596 reg = readl(&pdev->adma_regs->ep_sts); in cdns2_gadget_ep_enable()
1600 writel(pep->ring.dma, &pdev->adma_regs->ep_traddr); in cdns2_gadget_ep_enable()
1606 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_ep_enable()
1615 struct cdns2_device *pdev; in cdns2_gadget_ep_disable() local
1623 pdev = pep->pdev; in cdns2_gadget_ep_disable()
1625 if (dev_WARN_ONCE(pdev->dev, !(pep->ep_state & EP_ENABLED), in cdns2_gadget_ep_disable()
1629 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_ep_disable()
1633 cdns2_select_ep(pdev, ep->desc->bEndpointAddress); in cdns2_gadget_ep_disable()
1635 clear_reg_bit_32(&pdev->adma_regs->ep_cfg, DMA_EP_CFG_ENABLE); in cdns2_gadget_ep_disable()
1642 readl_poll_timeout_atomic(&pdev->adma_regs->ep_sts, val, in cdns2_gadget_ep_disable()
1644 writel(DMA_EP_CMD_EPRST, &pdev->adma_regs->ep_cmd); in cdns2_gadget_ep_disable()
1646 readl_poll_timeout_atomic(&pdev->adma_regs->ep_cmd, val, in cdns2_gadget_ep_disable()
1663 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_ep_disable()
1672 struct cdns2_device *pdev = pep->pdev; in cdns2_ep_enqueue() local
1680 ret = usb_gadget_map_request_by_dev(pdev->dev, request, pep->dir); in cdns2_ep_enqueue()
1690 cdns2_start_all_request(pdev, pep); in cdns2_ep_enqueue()
1701 struct cdns2_device *pdev; in cdns2_gadget_ep_queue() local
1709 pdev = pep->pdev; in cdns2_gadget_ep_queue()
1712 dev_err(pdev->dev, "%s: can't queue to disabled endpoint\n", in cdns2_gadget_ep_queue()
1717 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_ep_queue()
1727 zlp_request->buf = pdev->zlp_buf; in cdns2_gadget_ep_queue()
1734 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_ep_queue()
1754 dev_err(pep->pdev->dev, "%s: can't dequeue to disabled endpoint\n", in cdns2_gadget_ep_dequeue()
1763 spin_lock_irqsave(&pep->pdev->lock, flags); in cdns2_gadget_ep_dequeue()
1788 writel(DMA_EP_CMD_DFLUSH, &pep->pdev->adma_regs->ep_cmd); in cdns2_gadget_ep_dequeue()
1791 readl_poll_timeout_atomic(&pep->pdev->adma_regs->ep_cmd, val, in cdns2_gadget_ep_dequeue()
1818 spin_unlock_irqrestore(&pep->pdev->lock, flags); in cdns2_gadget_ep_dequeue()
1822 int cdns2_halt_endpoint(struct cdns2_device *pdev, in cdns2_halt_endpoint() argument
1834 conf = &pdev->epx_regs->ep[pep->num - 1].txcon; in cdns2_halt_endpoint()
1836 conf = &pdev->epx_regs->ep[pep->num - 1].rxcon; in cdns2_halt_endpoint()
1856 writeb(dir | pep->num, &pdev->epx_regs->endprst); in cdns2_halt_endpoint()
1858 &pdev->epx_regs->endprst); in cdns2_halt_endpoint()
1871 cdns2_start_all_request(pdev, pep); in cdns2_halt_endpoint()
1875 writeb(dir | pep->num, &pdev->epx_regs->endprst); in cdns2_halt_endpoint()
1877 &pdev->epx_regs->endprst); in cdns2_halt_endpoint()
1888 struct cdns2_device *pdev = pep->pdev; in cdns2_gadget_ep_set_halt() local
1893 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_ep_set_halt()
1905 ret = cdns2_halt_endpoint(pdev, pep, value); in cdns2_gadget_ep_set_halt()
1908 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_ep_set_halt()
1923 cdns2_endpoint *cdns2_find_available_ep(struct cdns2_device *pdev, in cdns2_find_available_ep() argument
1930 list_for_each_entry(ep, &pdev->gadget.ep_list, ep_list) { in cdns2_find_available_ep()
1965 struct cdns2_device *pdev = gadget_to_cdns2_device(gadget); in cdns2_gadget_match_ep() local
1969 pep = cdns2_find_available_ep(pdev, desc); in cdns2_gadget_match_ep()
1971 dev_err(pdev->dev, "no available ep\n"); in cdns2_gadget_match_ep()
1975 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_match_ep()
1983 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_match_ep()
2001 struct cdns2_device *pdev = gadget_to_cdns2_device(gadget); in cdns2_gadget_get_frame() local
2003 return readw(&pdev->usb_regs->frmnr); in cdns2_gadget_get_frame()
2008 struct cdns2_device *pdev = gadget_to_cdns2_device(gadget); in cdns2_gadget_wakeup() local
2011 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_wakeup()
2012 cdns2_wakeup(pdev); in cdns2_gadget_wakeup()
2013 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_wakeup()
2021 struct cdns2_device *pdev = gadget_to_cdns2_device(gadget); in cdns2_gadget_set_selfpowered() local
2024 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_set_selfpowered()
2025 pdev->is_selfpowered = !!is_selfpowered; in cdns2_gadget_set_selfpowered()
2026 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_set_selfpowered()
2031 static void cdns2_quiesce(struct cdns2_device *pdev) in cdns2_quiesce() argument
2033 set_reg_bit_8(&pdev->usb_regs->usbcs, USBCS_DISCON); in cdns2_quiesce()
2036 writeb(0, &pdev->interrupt_regs->extien), in cdns2_quiesce()
2037 writeb(0, &pdev->interrupt_regs->usbien), in cdns2_quiesce()
2038 writew(0, &pdev->adma_regs->ep_ien); in cdns2_quiesce()
2041 writeb(0x0, &pdev->interrupt_regs->usbirq); in cdns2_quiesce()
2044 static void cdns2_gadget_config(struct cdns2_device *pdev) in cdns2_gadget_config() argument
2046 cdns2_ep0_config(pdev); in cdns2_gadget_config()
2049 writel(~0x0, &pdev->adma_regs->ep_ien); in cdns2_gadget_config()
2050 cdns2_enable_l1(pdev, 0); in cdns2_gadget_config()
2051 writeb(USB_IEN_INIT, &pdev->interrupt_regs->usbien); in cdns2_gadget_config()
2052 writeb(EXTIRQ_WAKEUP, &pdev->interrupt_regs->extien); in cdns2_gadget_config()
2053 writel(DMA_CONF_DMULT, &pdev->adma_regs->conf); in cdns2_gadget_config()
2058 struct cdns2_device *pdev = gadget_to_cdns2_device(gadget); in cdns2_gadget_pullup() local
2067 disable_irq(pdev->irq); in cdns2_gadget_pullup()
2068 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_pullup()
2071 cdns2_gadget_config(pdev); in cdns2_gadget_pullup()
2072 clear_reg_bit_8(&pdev->usb_regs->usbcs, USBCS_DISCON); in cdns2_gadget_pullup()
2074 cdns2_quiesce(pdev); in cdns2_gadget_pullup()
2077 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_pullup()
2078 enable_irq(pdev->irq); in cdns2_gadget_pullup()
2086 struct cdns2_device *pdev = gadget_to_cdns2_device(gadget); in cdns2_gadget_udc_start() local
2090 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_udc_start()
2091 pdev->gadget_driver = driver; in cdns2_gadget_udc_start()
2098 writeb(SPEEDCTRL_HSDISABLE, &pdev->usb_regs->speedctrl); in cdns2_gadget_udc_start()
2101 writeb(0, &pdev->usb_regs->speedctrl); in cdns2_gadget_udc_start()
2104 dev_err(pdev->dev, "invalid maximum_speed parameter %d\n", in cdns2_gadget_udc_start()
2114 writeb(ENDPRST_IO_TX, &pdev->usb_regs->endprst); in cdns2_gadget_udc_start()
2116 &pdev->usb_regs->endprst); in cdns2_gadget_udc_start()
2117 writeb(ENDPRST_FIFORST | ENDPRST_TOGRST, &pdev->usb_regs->endprst); in cdns2_gadget_udc_start()
2119 cdns2_eps_onchip_buffer_init(pdev); in cdns2_gadget_udc_start()
2121 cdns2_gadget_config(pdev); in cdns2_gadget_udc_start()
2122 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_udc_start()
2129 struct cdns2_device *pdev = gadget_to_cdns2_device(gadget); in cdns2_gadget_udc_stop() local
2135 pdev->gadget_driver = NULL; in cdns2_gadget_udc_stop()
2136 pdev->gadget.speed = USB_SPEED_UNKNOWN; in cdns2_gadget_udc_stop()
2138 list_for_each_entry(ep, &pdev->gadget.ep_list, ep_list) { in cdns2_gadget_udc_stop()
2141 cdns2_select_ep(pdev, bEndpointAddress); in cdns2_gadget_udc_stop()
2142 writel(DMA_EP_CMD_EPRST, &pdev->adma_regs->ep_cmd); in cdns2_gadget_udc_stop()
2143 readl_poll_timeout_atomic(&pdev->adma_regs->ep_cmd, val, in cdns2_gadget_udc_stop()
2147 cdns2_quiesce(pdev); in cdns2_gadget_udc_stop()
2149 writeb(ENDPRST_IO_TX, &pdev->usb_regs->endprst); in cdns2_gadget_udc_stop()
2151 &pdev->epx_regs->endprst); in cdns2_gadget_udc_stop()
2152 writeb(ENDPRST_FIFORST | ENDPRST_TOGRST, &pdev->epx_regs->endprst); in cdns2_gadget_udc_stop()
2167 static void cdns2_free_all_eps(struct cdns2_device *pdev) in cdns2_free_all_eps() argument
2172 cdns2_free_tr_segment(&pdev->eps[i]); in cdns2_free_all_eps()
2176 static int cdns2_init_eps(struct cdns2_device *pdev) in cdns2_init_eps() argument
2189 if (!CDNS2_IF_EP_EXIST(pdev, epnum, direction)) in cdns2_init_eps()
2192 pep = &pdev->eps[i]; in cdns2_init_eps()
2193 pep->pdev = pdev; in cdns2_init_eps()
2206 cdns2_init_ep0(pdev, pep); in cdns2_init_eps()
2210 dev_err(pdev->dev, "Failed to init ep0\n"); in cdns2_init_eps()
2220 list_add_tail(&pep->endpoint.ep_list, &pdev->gadget.ep_list); in cdns2_init_eps()
2233 dev_dbg(pdev->dev, "Init %s, SupType: CTRL: %s, INT: %s, " in cdns2_init_eps()
2250 static int cdns2_gadget_start(struct cdns2_device *pdev) in cdns2_gadget_start() argument
2257 pdev->usb_regs = pdev->regs; in cdns2_gadget_start()
2258 pdev->ep0_regs = pdev->regs; in cdns2_gadget_start()
2259 pdev->epx_regs = pdev->regs; in cdns2_gadget_start()
2260 pdev->interrupt_regs = pdev->regs; in cdns2_gadget_start()
2261 pdev->adma_regs = pdev->regs + CDNS2_ADMA_REGS_OFFSET; in cdns2_gadget_start()
2264 set_reg_bit_8(&pdev->usb_regs->cpuctrl, CPUCTRL_SW_RST); in cdns2_gadget_start()
2266 ret = readl_poll_timeout_atomic(&pdev->usb_regs->cpuctrl, val, in cdns2_gadget_start()
2269 dev_err(pdev->dev, "Error: reset controller timeout\n"); in cdns2_gadget_start()
2273 usb_initialize_gadget(pdev->dev, &pdev->gadget, NULL); in cdns2_gadget_start()
2275 device_property_read_u16(pdev->dev, "cdns,on-chip-tx-buff-size", in cdns2_gadget_start()
2276 &pdev->onchip_tx_buf); in cdns2_gadget_start()
2277 device_property_read_u16(pdev->dev, "cdns,on-chip-rx-buff-size", in cdns2_gadget_start()
2278 &pdev->onchip_rx_buf); in cdns2_gadget_start()
2279 device_property_read_u32(pdev->dev, "cdns,avail-endpoints", in cdns2_gadget_start()
2280 &pdev->eps_supported); in cdns2_gadget_start()
2286 if (!pdev->onchip_tx_buf && !pdev->onchip_rx_buf) { in cdns2_gadget_start()
2288 dev_err(pdev->dev, "Invalid on-chip memory configuration\n"); in cdns2_gadget_start()
2292 if (!(pdev->eps_supported & ~0x00010001)) { in cdns2_gadget_start()
2294 dev_err(pdev->dev, "No hardware endpoints available\n"); in cdns2_gadget_start()
2298 max_speed = usb_get_maximum_speed(pdev->dev); in cdns2_gadget_start()
2305 dev_err(pdev->dev, "invalid maximum_speed parameter %d\n", in cdns2_gadget_start()
2313 pdev->gadget.max_speed = max_speed; in cdns2_gadget_start()
2314 pdev->gadget.speed = USB_SPEED_UNKNOWN; in cdns2_gadget_start()
2315 pdev->gadget.ops = &cdns2_gadget_ops; in cdns2_gadget_start()
2316 pdev->gadget.name = "usbhs-gadget"; in cdns2_gadget_start()
2317 pdev->gadget.quirk_avoids_skb_reserve = 1; in cdns2_gadget_start()
2318 pdev->gadget.irq = pdev->irq; in cdns2_gadget_start()
2320 spin_lock_init(&pdev->lock); in cdns2_gadget_start()
2321 INIT_WORK(&pdev->pending_status_wq, cdns2_pending_setup_status_handler); in cdns2_gadget_start()
2324 INIT_LIST_HEAD(&pdev->gadget.ep_list); in cdns2_gadget_start()
2325 pdev->eps_dma_pool = dma_pool_create("cdns2_eps_dma_pool", pdev->dev, in cdns2_gadget_start()
2327 if (!pdev->eps_dma_pool) { in cdns2_gadget_start()
2328 dev_err(pdev->dev, "Failed to create TRB dma pool\n"); in cdns2_gadget_start()
2333 ret = cdns2_init_eps(pdev); in cdns2_gadget_start()
2335 dev_err(pdev->dev, "Failed to create endpoints\n"); in cdns2_gadget_start()
2339 pdev->gadget.sg_supported = 1; in cdns2_gadget_start()
2341 pdev->zlp_buf = kzalloc(CDNS2_EP_ZLP_BUF_SIZE, GFP_KERNEL); in cdns2_gadget_start()
2342 if (!pdev->zlp_buf) { in cdns2_gadget_start()
2348 buf = dma_alloc_coherent(pdev->dev, 8, &pdev->ep0_preq.request.dma, in cdns2_gadget_start()
2350 pdev->ep0_preq.request.buf = buf; in cdns2_gadget_start()
2352 if (!pdev->ep0_preq.request.buf) { in cdns2_gadget_start()
2358 ret = usb_add_gadget(&pdev->gadget); in cdns2_gadget_start()
2360 dev_err(pdev->dev, "Failed to add gadget\n"); in cdns2_gadget_start()
2367 dma_free_coherent(pdev->dev, 8, pdev->ep0_preq.request.buf, in cdns2_gadget_start()
2368 pdev->ep0_preq.request.dma); in cdns2_gadget_start()
2370 kfree(pdev->zlp_buf); in cdns2_gadget_start()
2372 dma_pool_destroy(pdev->eps_dma_pool); in cdns2_gadget_start()
2374 usb_put_gadget(&pdev->gadget); in cdns2_gadget_start()
2379 int cdns2_gadget_suspend(struct cdns2_device *pdev) in cdns2_gadget_suspend() argument
2383 cdns2_disconnect_gadget(pdev); in cdns2_gadget_suspend()
2385 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_suspend()
2386 pdev->gadget.speed = USB_SPEED_UNKNOWN; in cdns2_gadget_suspend()
2389 usb_gadget_set_state(&pdev->gadget, USB_STATE_NOTATTACHED); in cdns2_gadget_suspend()
2390 cdns2_enable_l1(pdev, 0); in cdns2_gadget_suspend()
2393 writeb(0, &pdev->interrupt_regs->usbien); in cdns2_gadget_suspend()
2394 writel(0, &pdev->adma_regs->ep_ien); in cdns2_gadget_suspend()
2395 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_suspend()
2400 int cdns2_gadget_resume(struct cdns2_device *pdev, bool hibernated) in cdns2_gadget_resume() argument
2404 spin_lock_irqsave(&pdev->lock, flags); in cdns2_gadget_resume()
2406 if (!pdev->gadget_driver) { in cdns2_gadget_resume()
2407 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_resume()
2411 cdns2_gadget_config(pdev); in cdns2_gadget_resume()
2414 clear_reg_bit_8(&pdev->usb_regs->usbcs, USBCS_DISCON); in cdns2_gadget_resume()
2416 spin_unlock_irqrestore(&pdev->lock, flags); in cdns2_gadget_resume()
2421 void cdns2_gadget_remove(struct cdns2_device *pdev) in cdns2_gadget_remove() argument
2423 pm_runtime_mark_last_busy(pdev->dev); in cdns2_gadget_remove()
2424 pm_runtime_put_autosuspend(pdev->dev); in cdns2_gadget_remove()
2426 usb_del_gadget(&pdev->gadget); in cdns2_gadget_remove()
2427 cdns2_free_all_eps(pdev); in cdns2_gadget_remove()
2429 dma_pool_destroy(pdev->eps_dma_pool); in cdns2_gadget_remove()
2430 kfree(pdev->zlp_buf); in cdns2_gadget_remove()
2431 usb_put_gadget(&pdev->gadget); in cdns2_gadget_remove()
2434 int cdns2_gadget_init(struct cdns2_device *pdev) in cdns2_gadget_init() argument
2439 ret = dma_set_mask_and_coherent(pdev->dev, DMA_BIT_MASK(32)); in cdns2_gadget_init()
2441 dev_err(pdev->dev, "Failed to set dma mask: %d\n", ret); in cdns2_gadget_init()
2445 pm_runtime_get_sync(pdev->dev); in cdns2_gadget_init()
2447 cdsn2_isoc_burst_opt(pdev); in cdns2_gadget_init()
2449 ret = cdns2_gadget_start(pdev); in cdns2_gadget_init()
2451 pm_runtime_put_sync(pdev->dev); in cdns2_gadget_init()
2459 ret = devm_request_threaded_irq(pdev->dev, pdev->irq, in cdns2_gadget_init()
2463 dev_name(pdev->dev), in cdns2_gadget_init()
2464 pdev); in cdns2_gadget_init()
2471 cdns2_gadget_remove(pdev); in cdns2_gadget_init()