Lines Matching refs:udc
216 struct bcm63xx_udc *udc; member
241 struct bcm63xx_udc *udc; member
354 static inline u32 usbd_readl(struct bcm63xx_udc *udc, u32 off) in usbd_readl() argument
356 return bcm_readl(udc->usbd_regs + off); in usbd_readl()
359 static inline void usbd_writel(struct bcm63xx_udc *udc, u32 val, u32 off) in usbd_writel() argument
361 bcm_writel(val, udc->usbd_regs + off); in usbd_writel()
364 static inline u32 usb_dma_readl(struct bcm63xx_udc *udc, u32 off) in usb_dma_readl() argument
366 return bcm_readl(udc->iudma_regs + off); in usb_dma_readl()
369 static inline void usb_dma_writel(struct bcm63xx_udc *udc, u32 val, u32 off) in usb_dma_writel() argument
371 bcm_writel(val, udc->iudma_regs + off); in usb_dma_writel()
374 static inline u32 usb_dmac_readl(struct bcm63xx_udc *udc, u32 off, int chan) in usb_dmac_readl() argument
376 return bcm_readl(udc->iudma_regs + IUDMA_DMAC_OFFSET + off + in usb_dmac_readl()
380 static inline void usb_dmac_writel(struct bcm63xx_udc *udc, u32 val, u32 off, in usb_dmac_writel() argument
383 bcm_writel(val, udc->iudma_regs + IUDMA_DMAC_OFFSET + off + in usb_dmac_writel()
387 static inline u32 usb_dmas_readl(struct bcm63xx_udc *udc, u32 off, int chan) in usb_dmas_readl() argument
389 return bcm_readl(udc->iudma_regs + IUDMA_DMAS_OFFSET + off + in usb_dmas_readl()
393 static inline void usb_dmas_writel(struct bcm63xx_udc *udc, u32 val, u32 off, in usb_dmas_writel() argument
396 bcm_writel(val, udc->iudma_regs + IUDMA_DMAS_OFFSET + off + in usb_dmas_writel()
400 static inline void set_clocks(struct bcm63xx_udc *udc, bool is_enabled) in set_clocks() argument
403 clk_enable(udc->usbh_clk); in set_clocks()
404 clk_enable(udc->usbd_clk); in set_clocks()
407 clk_disable(udc->usbd_clk); in set_clocks()
408 clk_disable(udc->usbh_clk); in set_clocks()
425 static void bcm63xx_ep_dma_select(struct bcm63xx_udc *udc, int idx) in bcm63xx_ep_dma_select() argument
427 u32 val = usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_ep_dma_select()
431 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_ep_dma_select()
443 static void bcm63xx_set_stall(struct bcm63xx_udc *udc, struct bcm63xx_ep *bep, in bcm63xx_set_stall() argument
451 usbd_writel(udc, val, USBD_STALL_REG); in bcm63xx_set_stall()
461 static void bcm63xx_fifo_setup(struct bcm63xx_udc *udc) in bcm63xx_fifo_setup() argument
463 int is_hs = udc->gadget.speed == USB_SPEED_HIGH; in bcm63xx_fifo_setup()
472 bcm63xx_ep_dma_select(udc, i >> 1); in bcm63xx_fifo_setup()
478 usbd_writel(udc, val, USBD_RXFIFO_CONFIG_REG); in bcm63xx_fifo_setup()
479 usbd_writel(udc, in bcm63xx_fifo_setup()
487 usbd_writel(udc, val, USBD_TXFIFO_CONFIG_REG); in bcm63xx_fifo_setup()
488 usbd_writel(udc, in bcm63xx_fifo_setup()
492 usbd_readl(udc, USBD_TXFIFO_EPSIZE_REG); in bcm63xx_fifo_setup()
501 static void bcm63xx_fifo_reset_ep(struct bcm63xx_udc *udc, int ep_num) in bcm63xx_fifo_reset_ep() argument
505 bcm63xx_ep_dma_select(udc, ep_num); in bcm63xx_fifo_reset_ep()
507 val = usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
509 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
510 usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
517 static void bcm63xx_fifo_reset(struct bcm63xx_udc *udc) in bcm63xx_fifo_reset() argument
522 bcm63xx_fifo_reset_ep(udc, i); in bcm63xx_fifo_reset()
529 static void bcm63xx_ep_init(struct bcm63xx_udc *udc) in bcm63xx_ep_init() argument
539 bcm63xx_ep_dma_select(udc, cfg->ep_num); in bcm63xx_ep_init()
542 usbd_writel(udc, val, USBD_EPNUM_TYPEMAP_REG); in bcm63xx_ep_init()
552 static void bcm63xx_ep_setup(struct bcm63xx_udc *udc) in bcm63xx_ep_setup() argument
556 usbd_writel(udc, USBD_CSR_SETUPADDR_DEF, USBD_CSR_SETUPADDR_REG); in bcm63xx_ep_setup()
560 int max_pkt = udc->gadget.speed == USB_SPEED_HIGH ? in bcm63xx_ep_setup()
564 udc->iudma[i].max_pkt = max_pkt; in bcm63xx_ep_setup()
568 usb_ep_set_maxpacket_limit(&udc->bep[idx].ep, max_pkt); in bcm63xx_ep_setup()
573 (udc->cfg << USBD_CSR_EP_CFG_SHIFT) | in bcm63xx_ep_setup()
574 (udc->iface << USBD_CSR_EP_IFACE_SHIFT) | in bcm63xx_ep_setup()
575 (udc->alt_iface << USBD_CSR_EP_ALTIFACE_SHIFT) | in bcm63xx_ep_setup()
577 usbd_writel(udc, val, USBD_CSR_EP_REG(idx)); in bcm63xx_ep_setup()
594 static void iudma_write(struct bcm63xx_udc *udc, struct iudma_ch *iudma, in iudma_write() argument
657 usb_dmac_writel(udc, ENETDMAC_CHANCFG_EN_MASK, in iudma_write()
670 static int iudma_read(struct bcm63xx_udc *udc, struct iudma_ch *iudma) in iudma_read() argument
704 static void iudma_reset_channel(struct bcm63xx_udc *udc, struct iudma_ch *iudma) in iudma_reset_channel() argument
711 bcm63xx_fifo_reset_ep(udc, max(0, iudma->ep_num)); in iudma_reset_channel()
714 usb_dmac_writel(udc, 0, ENETDMAC_CHANCFG_REG, ch_idx); in iudma_reset_channel()
716 while (usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx) & in iudma_reset_channel()
722 bcm63xx_fifo_reset_ep(udc, iudma->ep_num); in iudma_reset_channel()
725 dev_err(udc->dev, "can't reset IUDMA channel %d\n", in iudma_reset_channel()
730 dev_warn(udc->dev, "forcibly halting IUDMA channel %d\n", in iudma_reset_channel()
732 usb_dmac_writel(udc, ENETDMAC_CHANCFG_BUFHALT_MASK, in iudma_reset_channel()
736 usb_dmac_writel(udc, ~0, ENETDMAC_IR_REG, ch_idx); in iudma_reset_channel()
747 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, in iudma_reset_channel()
749 usb_dmac_writel(udc, 8, ENETDMAC_MAXBURST_REG, ch_idx); in iudma_reset_channel()
751 usb_dmas_writel(udc, iudma->bd_ring_dma, ENETDMAS_RSTART_REG, ch_idx); in iudma_reset_channel()
752 usb_dmas_writel(udc, 0, ENETDMAS_SRAM2_REG, ch_idx); in iudma_reset_channel()
760 static int iudma_init_channel(struct bcm63xx_udc *udc, unsigned int ch_idx) in iudma_init_channel() argument
762 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in iudma_init_channel()
771 bep = &udc->bep[iudma->ep_num]; in iudma_init_channel()
777 iudma->udc = udc; in iudma_init_channel()
784 iudma->bd_ring = dmam_alloc_coherent(udc->dev, in iudma_init_channel()
800 static int iudma_init(struct bcm63xx_udc *udc) in iudma_init() argument
804 usb_dma_writel(udc, ENETDMA_CFG_EN_MASK, ENETDMA_CFG_REG); in iudma_init()
807 rc = iudma_init_channel(udc, i); in iudma_init()
810 iudma_reset_channel(udc, &udc->iudma[i]); in iudma_init()
813 usb_dma_writel(udc, BIT(BCM63XX_NUM_IUDMA)-1, ENETDMA_GLB_IRQMASK_REG); in iudma_init()
823 static void iudma_uninit(struct bcm63xx_udc *udc) in iudma_uninit() argument
827 usb_dma_writel(udc, 0, ENETDMA_GLB_IRQMASK_REG); in iudma_uninit()
830 iudma_reset_channel(udc, &udc->iudma[i]); in iudma_uninit()
832 usb_dma_writel(udc, 0, ENETDMA_CFG_REG); in iudma_uninit()
844 static void bcm63xx_set_ctrl_irqs(struct bcm63xx_udc *udc, bool enable_irqs) in bcm63xx_set_ctrl_irqs() argument
848 usbd_writel(udc, 0, USBD_STATUS_REG); in bcm63xx_set_ctrl_irqs()
855 usbd_writel(udc, enable_irqs ? val : 0, USBD_EVENT_IRQ_MASK_REG); in bcm63xx_set_ctrl_irqs()
856 usbd_writel(udc, val, USBD_EVENT_IRQ_STATUS_REG); in bcm63xx_set_ctrl_irqs()
870 static void bcm63xx_select_phy_mode(struct bcm63xx_udc *udc, bool is_device) in bcm63xx_select_phy_mode() argument
872 u32 val, portmask = BIT(udc->pd->port_no); in bcm63xx_select_phy_mode()
910 static void bcm63xx_select_pullup(struct bcm63xx_udc *udc, bool is_on) in bcm63xx_select_pullup() argument
912 u32 val, portmask = BIT(udc->pd->port_no); in bcm63xx_select_pullup()
929 static void bcm63xx_uninit_udc_hw(struct bcm63xx_udc *udc) in bcm63xx_uninit_udc_hw() argument
931 set_clocks(udc, true); in bcm63xx_uninit_udc_hw()
932 iudma_uninit(udc); in bcm63xx_uninit_udc_hw()
933 set_clocks(udc, false); in bcm63xx_uninit_udc_hw()
935 clk_put(udc->usbd_clk); in bcm63xx_uninit_udc_hw()
936 clk_put(udc->usbh_clk); in bcm63xx_uninit_udc_hw()
943 static int bcm63xx_init_udc_hw(struct bcm63xx_udc *udc) in bcm63xx_init_udc_hw() argument
948 udc->ep0_ctrl_buf = devm_kzalloc(udc->dev, BCM63XX_MAX_CTRL_PKT, in bcm63xx_init_udc_hw()
950 if (!udc->ep0_ctrl_buf) in bcm63xx_init_udc_hw()
953 INIT_LIST_HEAD(&udc->gadget.ep_list); in bcm63xx_init_udc_hw()
955 struct bcm63xx_ep *bep = &udc->bep[i]; in bcm63xx_init_udc_hw()
961 list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list); in bcm63xx_init_udc_hw()
964 bep->udc = udc; in bcm63xx_init_udc_hw()
969 udc->gadget.ep0 = &udc->bep[0].ep; in bcm63xx_init_udc_hw()
970 list_del(&udc->bep[0].ep.ep_list); in bcm63xx_init_udc_hw()
972 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_init_udc_hw()
973 udc->ep0state = EP0_SHUTDOWN; in bcm63xx_init_udc_hw()
975 udc->usbh_clk = clk_get(udc->dev, "usbh"); in bcm63xx_init_udc_hw()
976 if (IS_ERR(udc->usbh_clk)) in bcm63xx_init_udc_hw()
979 udc->usbd_clk = clk_get(udc->dev, "usbd"); in bcm63xx_init_udc_hw()
980 if (IS_ERR(udc->usbd_clk)) { in bcm63xx_init_udc_hw()
981 clk_put(udc->usbh_clk); in bcm63xx_init_udc_hw()
985 set_clocks(udc, true); in bcm63xx_init_udc_hw()
990 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_init_udc_hw()
998 if (udc->gadget.max_speed == USB_SPEED_HIGH) in bcm63xx_init_udc_hw()
1002 usbd_writel(udc, val, USBD_STRAPS_REG); in bcm63xx_init_udc_hw()
1004 bcm63xx_set_ctrl_irqs(udc, false); in bcm63xx_init_udc_hw()
1006 usbd_writel(udc, 0, USBD_EVENT_IRQ_CFG_LO_REG); in bcm63xx_init_udc_hw()
1010 usbd_writel(udc, val, USBD_EVENT_IRQ_CFG_HI_REG); in bcm63xx_init_udc_hw()
1012 rc = iudma_init(udc); in bcm63xx_init_udc_hw()
1013 set_clocks(udc, false); in bcm63xx_init_udc_hw()
1015 bcm63xx_uninit_udc_hw(udc); in bcm63xx_init_udc_hw()
1036 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_ep_enable() local
1043 if (!udc->driver) in bcm63xx_ep_enable()
1046 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_enable()
1048 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_enable()
1055 iudma_reset_channel(udc, iudma); in bcm63xx_ep_enable()
1058 bcm63xx_set_stall(udc, bep, false); in bcm63xx_ep_enable()
1059 clear_bit(bep->ep_num, &udc->wedgemap); in bcm63xx_ep_enable()
1064 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_enable()
1075 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_ep_disable() local
1083 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_disable()
1085 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1090 iudma_reset_channel(udc, iudma); in bcm63xx_ep_disable()
1094 usb_gadget_unmap_request(&udc->gadget, &breq->req, in bcm63xx_ep_disable()
1099 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1101 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_disable()
1106 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1156 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_queue() local
1168 if (bep == &udc->bep[0]) { in bcm63xx_udc_queue()
1170 if (udc->ep0_reply) in bcm63xx_udc_queue()
1173 udc->ep0_reply = req; in bcm63xx_udc_queue()
1174 schedule_work(&udc->ep0_wq); in bcm63xx_udc_queue()
1178 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_queue()
1184 rc = usb_gadget_map_request(&udc->gadget, req, bep->iudma->is_tx); in bcm63xx_udc_queue()
1188 iudma_write(udc, bep->iudma, breq); in bcm63xx_udc_queue()
1192 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_queue()
1208 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_dequeue() local
1213 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_dequeue()
1220 usb_gadget_unmap_request(&udc->gadget, &breq->req, bep->iudma->is_tx); in bcm63xx_udc_dequeue()
1223 iudma_reset_channel(udc, bep->iudma); in bcm63xx_udc_dequeue()
1231 iudma_write(udc, bep->iudma, next); in bcm63xx_udc_dequeue()
1238 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_dequeue()
1256 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_set_halt() local
1259 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_set_halt()
1260 bcm63xx_set_stall(udc, bep, !!value); in bcm63xx_udc_set_halt()
1262 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_set_halt()
1276 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_set_wedge() local
1279 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_set_wedge()
1280 set_bit(bep->ep_num, &udc->wedgemap); in bcm63xx_udc_set_wedge()
1281 bcm63xx_set_stall(udc, bep, true); in bcm63xx_udc_set_wedge()
1282 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_set_wedge()
1310 static int bcm63xx_ep0_setup_callback(struct bcm63xx_udc *udc, in bcm63xx_ep0_setup_callback() argument
1315 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_setup_callback()
1316 rc = udc->driver->setup(&udc->gadget, ctrl); in bcm63xx_ep0_setup_callback()
1317 spin_lock_irq(&udc->lock); in bcm63xx_ep0_setup_callback()
1333 static int bcm63xx_ep0_spoof_set_cfg(struct bcm63xx_udc *udc) in bcm63xx_ep0_spoof_set_cfg() argument
1340 ctrl.wValue = cpu_to_le16(udc->cfg); in bcm63xx_ep0_spoof_set_cfg()
1344 rc = bcm63xx_ep0_setup_callback(udc, &ctrl); in bcm63xx_ep0_spoof_set_cfg()
1346 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_spoof_set_cfg()
1348 udc->cfg); in bcm63xx_ep0_spoof_set_cfg()
1357 static int bcm63xx_ep0_spoof_set_iface(struct bcm63xx_udc *udc) in bcm63xx_ep0_spoof_set_iface() argument
1364 ctrl.wValue = cpu_to_le16(udc->alt_iface); in bcm63xx_ep0_spoof_set_iface()
1365 ctrl.wIndex = cpu_to_le16(udc->iface); in bcm63xx_ep0_spoof_set_iface()
1368 rc = bcm63xx_ep0_setup_callback(udc, &ctrl); in bcm63xx_ep0_spoof_set_iface()
1370 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_spoof_set_iface()
1372 udc->iface, udc->alt_iface); in bcm63xx_ep0_spoof_set_iface()
1383 static void bcm63xx_ep0_map_write(struct bcm63xx_udc *udc, int ch_idx, in bcm63xx_ep0_map_write() argument
1387 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in bcm63xx_ep0_map_write()
1389 BUG_ON(udc->ep0_request); in bcm63xx_ep0_map_write()
1390 udc->ep0_request = req; in bcm63xx_ep0_map_write()
1394 usb_gadget_map_request(&udc->gadget, req, iudma->is_tx); in bcm63xx_ep0_map_write()
1395 iudma_write(udc, iudma, breq); in bcm63xx_ep0_map_write()
1404 static void bcm63xx_ep0_complete(struct bcm63xx_udc *udc, in bcm63xx_ep0_complete() argument
1411 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_complete()
1412 req->complete(&udc->bep[0].ep, req); in bcm63xx_ep0_complete()
1413 spin_lock_irq(&udc->lock); in bcm63xx_ep0_complete()
1423 static void bcm63xx_ep0_nuke_reply(struct bcm63xx_udc *udc, int is_tx) in bcm63xx_ep0_nuke_reply() argument
1425 struct usb_request *req = udc->ep0_reply; in bcm63xx_ep0_nuke_reply()
1427 udc->ep0_reply = NULL; in bcm63xx_ep0_nuke_reply()
1428 usb_gadget_unmap_request(&udc->gadget, req, is_tx); in bcm63xx_ep0_nuke_reply()
1429 if (udc->ep0_request == req) { in bcm63xx_ep0_nuke_reply()
1430 udc->ep0_req_completed = 0; in bcm63xx_ep0_nuke_reply()
1431 udc->ep0_request = NULL; in bcm63xx_ep0_nuke_reply()
1433 bcm63xx_ep0_complete(udc, req, -ESHUTDOWN); in bcm63xx_ep0_nuke_reply()
1441 static int bcm63xx_ep0_read_complete(struct bcm63xx_udc *udc) in bcm63xx_ep0_read_complete() argument
1443 struct usb_request *req = udc->ep0_request; in bcm63xx_ep0_read_complete()
1445 udc->ep0_req_completed = 0; in bcm63xx_ep0_read_complete()
1446 udc->ep0_request = NULL; in bcm63xx_ep0_read_complete()
1460 static void bcm63xx_ep0_internal_request(struct bcm63xx_udc *udc, int ch_idx, in bcm63xx_ep0_internal_request() argument
1463 struct usb_request *req = &udc->ep0_ctrl_req.req; in bcm63xx_ep0_internal_request()
1465 req->buf = udc->ep0_ctrl_buf; in bcm63xx_ep0_internal_request()
1469 bcm63xx_ep0_map_write(udc, ch_idx, req); in bcm63xx_ep0_internal_request()
1480 static enum bcm63xx_ep0_state bcm63xx_ep0_do_setup(struct bcm63xx_udc *udc) in bcm63xx_ep0_do_setup() argument
1483 struct usb_ctrlrequest *ctrl = (void *)udc->ep0_ctrl_buf; in bcm63xx_ep0_do_setup()
1485 rc = bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_do_setup()
1488 dev_err(udc->dev, "missing SETUP packet\n"); in bcm63xx_ep0_do_setup()
1502 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_do_setup()
1508 rc = bcm63xx_ep0_setup_callback(udc, ctrl); in bcm63xx_ep0_do_setup()
1510 bcm63xx_set_stall(udc, &udc->bep[0], true); in bcm63xx_ep0_do_setup()
1533 static int bcm63xx_ep0_do_idle(struct bcm63xx_udc *udc) in bcm63xx_ep0_do_idle() argument
1535 if (udc->ep0_req_reset) { in bcm63xx_ep0_do_idle()
1536 udc->ep0_req_reset = 0; in bcm63xx_ep0_do_idle()
1537 } else if (udc->ep0_req_set_cfg) { in bcm63xx_ep0_do_idle()
1538 udc->ep0_req_set_cfg = 0; in bcm63xx_ep0_do_idle()
1539 if (bcm63xx_ep0_spoof_set_cfg(udc) >= 0) in bcm63xx_ep0_do_idle()
1540 udc->ep0state = EP0_IN_FAKE_STATUS_PHASE; in bcm63xx_ep0_do_idle()
1541 } else if (udc->ep0_req_set_iface) { in bcm63xx_ep0_do_idle()
1542 udc->ep0_req_set_iface = 0; in bcm63xx_ep0_do_idle()
1543 if (bcm63xx_ep0_spoof_set_iface(udc) >= 0) in bcm63xx_ep0_do_idle()
1544 udc->ep0state = EP0_IN_FAKE_STATUS_PHASE; in bcm63xx_ep0_do_idle()
1545 } else if (udc->ep0_req_completed) { in bcm63xx_ep0_do_idle()
1546 udc->ep0state = bcm63xx_ep0_do_setup(udc); in bcm63xx_ep0_do_idle()
1547 return udc->ep0state == EP0_IDLE ? -EAGAIN : 0; in bcm63xx_ep0_do_idle()
1548 } else if (udc->ep0_req_shutdown) { in bcm63xx_ep0_do_idle()
1549 udc->ep0_req_shutdown = 0; in bcm63xx_ep0_do_idle()
1550 udc->ep0_req_completed = 0; in bcm63xx_ep0_do_idle()
1551 udc->ep0_request = NULL; in bcm63xx_ep0_do_idle()
1552 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_RXCHAN]); in bcm63xx_ep0_do_idle()
1553 usb_gadget_unmap_request(&udc->gadget, in bcm63xx_ep0_do_idle()
1554 &udc->ep0_ctrl_req.req, 0); in bcm63xx_ep0_do_idle()
1558 udc->ep0state = EP0_SHUTDOWN; in bcm63xx_ep0_do_idle()
1559 } else if (udc->ep0_reply) { in bcm63xx_ep0_do_idle()
1565 dev_warn(udc->dev, "nuking unexpected reply\n"); in bcm63xx_ep0_do_idle()
1566 bcm63xx_ep0_nuke_reply(udc, 0); in bcm63xx_ep0_do_idle()
1580 static int bcm63xx_ep0_one_round(struct bcm63xx_udc *udc) in bcm63xx_ep0_one_round() argument
1582 enum bcm63xx_ep0_state ep0state = udc->ep0state; in bcm63xx_ep0_one_round()
1583 bool shutdown = udc->ep0_req_reset || udc->ep0_req_shutdown; in bcm63xx_ep0_one_round()
1585 switch (udc->ep0state) { in bcm63xx_ep0_one_round()
1588 bcm63xx_ep0_internal_request(udc, IUDMA_EP0_RXCHAN, in bcm63xx_ep0_one_round()
1593 return bcm63xx_ep0_do_idle(udc); in bcm63xx_ep0_one_round()
1604 if (udc->ep0_reply) { in bcm63xx_ep0_one_round()
1605 bcm63xx_ep0_map_write(udc, IUDMA_EP0_TXCHAN, in bcm63xx_ep0_one_round()
1606 udc->ep0_reply); in bcm63xx_ep0_one_round()
1620 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1621 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1622 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1629 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_TXCHAN]); in bcm63xx_ep0_one_round()
1630 bcm63xx_ep0_nuke_reply(udc, 1); in bcm63xx_ep0_one_round()
1637 if (udc->ep0_reply) { in bcm63xx_ep0_one_round()
1638 bcm63xx_ep0_map_write(udc, IUDMA_EP0_RXCHAN, in bcm63xx_ep0_one_round()
1639 udc->ep0_reply); in bcm63xx_ep0_one_round()
1647 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1648 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1649 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1652 bcm63xx_ep0_internal_request(udc, IUDMA_EP0_TXCHAN, 0); in bcm63xx_ep0_one_round()
1655 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_RXCHAN]); in bcm63xx_ep0_one_round()
1656 bcm63xx_ep0_nuke_reply(udc, 0); in bcm63xx_ep0_one_round()
1670 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1671 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1674 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_TXCHAN]); in bcm63xx_ep0_one_round()
1675 udc->ep0_request = NULL; in bcm63xx_ep0_one_round()
1694 struct usb_request *r = udc->ep0_reply; in bcm63xx_ep0_one_round()
1702 bcm63xx_ep0_complete(udc, r, 0); in bcm63xx_ep0_one_round()
1703 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1711 if (udc->ep0state == ep0state) in bcm63xx_ep0_one_round()
1714 udc->ep0state = ep0state; in bcm63xx_ep0_one_round()
1734 struct bcm63xx_udc *udc = container_of(w, struct bcm63xx_udc, ep0_wq); in bcm63xx_ep0_process() local
1735 spin_lock_irq(&udc->lock); in bcm63xx_ep0_process()
1736 while (bcm63xx_ep0_one_round(udc) == 0) in bcm63xx_ep0_process()
1738 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_process()
1751 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_get_frame() local
1753 return (usbd_readl(udc, USBD_STATUS_REG) & in bcm63xx_udc_get_frame()
1766 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_pullup() local
1770 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_pullup()
1771 if (is_on && udc->ep0state == EP0_SHUTDOWN) { in bcm63xx_udc_pullup()
1772 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_udc_pullup()
1773 udc->ep0state = EP0_REQUEUE; in bcm63xx_udc_pullup()
1774 bcm63xx_fifo_setup(udc); in bcm63xx_udc_pullup()
1775 bcm63xx_fifo_reset(udc); in bcm63xx_udc_pullup()
1776 bcm63xx_ep_setup(udc); in bcm63xx_udc_pullup()
1778 bitmap_zero(&udc->wedgemap, BCM63XX_NUM_EP); in bcm63xx_udc_pullup()
1780 bcm63xx_set_stall(udc, &udc->bep[i], false); in bcm63xx_udc_pullup()
1782 bcm63xx_set_ctrl_irqs(udc, true); in bcm63xx_udc_pullup()
1785 } else if (!is_on && udc->ep0state != EP0_SHUTDOWN) { in bcm63xx_udc_pullup()
1788 udc->ep0_req_shutdown = 1; in bcm63xx_udc_pullup()
1789 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_pullup()
1792 schedule_work(&udc->ep0_wq); in bcm63xx_udc_pullup()
1793 if (udc->ep0state == EP0_SHUTDOWN) in bcm63xx_udc_pullup()
1797 bcm63xx_set_ctrl_irqs(udc, false); in bcm63xx_udc_pullup()
1798 cancel_work_sync(&udc->ep0_wq); in bcm63xx_udc_pullup()
1802 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_pullup()
1814 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_start() local
1820 if (!udc) in bcm63xx_udc_start()
1822 if (udc->driver) in bcm63xx_udc_start()
1825 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_start()
1827 set_clocks(udc, true); in bcm63xx_udc_start()
1828 bcm63xx_fifo_setup(udc); in bcm63xx_udc_start()
1829 bcm63xx_ep_init(udc); in bcm63xx_udc_start()
1830 bcm63xx_ep_setup(udc); in bcm63xx_udc_start()
1831 bcm63xx_fifo_reset(udc); in bcm63xx_udc_start()
1832 bcm63xx_select_phy_mode(udc, true); in bcm63xx_udc_start()
1834 udc->driver = driver; in bcm63xx_udc_start()
1836 udc->gadget.dev.of_node = udc->dev->of_node; in bcm63xx_udc_start()
1838 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_start()
1850 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_stop() local
1853 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_stop()
1855 udc->driver = NULL; in bcm63xx_udc_stop()
1865 bcm63xx_select_phy_mode(udc, false); in bcm63xx_udc_stop()
1866 set_clocks(udc, false); in bcm63xx_udc_stop()
1868 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_stop()
1893 static void bcm63xx_update_cfg_iface(struct bcm63xx_udc *udc) in bcm63xx_update_cfg_iface() argument
1895 u32 reg = usbd_readl(udc, USBD_STATUS_REG); in bcm63xx_update_cfg_iface()
1897 udc->cfg = (reg & USBD_STATUS_CFG_MASK) >> USBD_STATUS_CFG_SHIFT; in bcm63xx_update_cfg_iface()
1898 udc->iface = (reg & USBD_STATUS_INTF_MASK) >> USBD_STATUS_INTF_SHIFT; in bcm63xx_update_cfg_iface()
1899 udc->alt_iface = (reg & USBD_STATUS_ALTINTF_MASK) >> in bcm63xx_update_cfg_iface()
1901 bcm63xx_ep_setup(udc); in bcm63xx_update_cfg_iface()
1911 static int bcm63xx_update_link_speed(struct bcm63xx_udc *udc) in bcm63xx_update_link_speed() argument
1913 u32 reg = usbd_readl(udc, USBD_STATUS_REG); in bcm63xx_update_link_speed()
1914 enum usb_device_speed oldspeed = udc->gadget.speed; in bcm63xx_update_link_speed()
1918 udc->gadget.speed = USB_SPEED_HIGH; in bcm63xx_update_link_speed()
1921 udc->gadget.speed = USB_SPEED_FULL; in bcm63xx_update_link_speed()
1925 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_update_link_speed()
1926 dev_err(udc->dev, in bcm63xx_update_link_speed()
1931 if (udc->gadget.speed != oldspeed) { in bcm63xx_update_link_speed()
1932 dev_info(udc->dev, "link up, %s-speed mode\n", in bcm63xx_update_link_speed()
1933 udc->gadget.speed == USB_SPEED_HIGH ? "high" : "full"); in bcm63xx_update_link_speed()
1951 static void bcm63xx_update_wedge(struct bcm63xx_udc *udc, bool new_status) in bcm63xx_update_wedge() argument
1955 for_each_set_bit(i, &udc->wedgemap, BCM63XX_NUM_EP) { in bcm63xx_update_wedge()
1956 bcm63xx_set_stall(udc, &udc->bep[i], new_status); in bcm63xx_update_wedge()
1958 clear_bit(i, &udc->wedgemap); in bcm63xx_update_wedge()
1972 struct bcm63xx_udc *udc = dev_id; in bcm63xx_udc_ctrl_isr() local
1976 stat = usbd_readl(udc, USBD_EVENT_IRQ_STATUS_REG) & in bcm63xx_udc_ctrl_isr()
1977 usbd_readl(udc, USBD_EVENT_IRQ_MASK_REG); in bcm63xx_udc_ctrl_isr()
1979 usbd_writel(udc, stat, USBD_EVENT_IRQ_STATUS_REG); in bcm63xx_udc_ctrl_isr()
1981 spin_lock(&udc->lock); in bcm63xx_udc_ctrl_isr()
1985 if (!(usbd_readl(udc, USBD_EVENTS_REG) & in bcm63xx_udc_ctrl_isr()
1987 udc->gadget.speed != USB_SPEED_UNKNOWN) in bcm63xx_udc_ctrl_isr()
1988 dev_info(udc->dev, "link down\n"); in bcm63xx_udc_ctrl_isr()
1990 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_udc_ctrl_isr()
1994 bcm63xx_fifo_setup(udc); in bcm63xx_udc_ctrl_isr()
1995 bcm63xx_fifo_reset(udc); in bcm63xx_udc_ctrl_isr()
1996 bcm63xx_ep_setup(udc); in bcm63xx_udc_ctrl_isr()
1998 bcm63xx_update_wedge(udc, false); in bcm63xx_udc_ctrl_isr()
2000 udc->ep0_req_reset = 1; in bcm63xx_udc_ctrl_isr()
2001 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2005 if (bcm63xx_update_link_speed(udc)) { in bcm63xx_udc_ctrl_isr()
2006 bcm63xx_fifo_setup(udc); in bcm63xx_udc_ctrl_isr()
2007 bcm63xx_ep_setup(udc); in bcm63xx_udc_ctrl_isr()
2009 bcm63xx_update_wedge(udc, true); in bcm63xx_udc_ctrl_isr()
2012 bcm63xx_update_cfg_iface(udc); in bcm63xx_udc_ctrl_isr()
2013 udc->ep0_req_set_cfg = 1; in bcm63xx_udc_ctrl_isr()
2014 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2017 bcm63xx_update_cfg_iface(udc); in bcm63xx_udc_ctrl_isr()
2018 udc->ep0_req_set_iface = 1; in bcm63xx_udc_ctrl_isr()
2019 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2021 spin_unlock(&udc->lock); in bcm63xx_udc_ctrl_isr()
2023 if (disconnected && udc->driver) in bcm63xx_udc_ctrl_isr()
2024 udc->driver->disconnect(&udc->gadget); in bcm63xx_udc_ctrl_isr()
2025 else if (bus_reset && udc->driver) in bcm63xx_udc_ctrl_isr()
2026 usb_gadget_udc_reset(&udc->gadget, udc->driver); in bcm63xx_udc_ctrl_isr()
2044 struct bcm63xx_udc *udc = iudma->udc; in bcm63xx_udc_data_isr() local
2051 spin_lock(&udc->lock); in bcm63xx_udc_data_isr()
2053 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, in bcm63xx_udc_data_isr()
2056 rc = iudma_read(udc, iudma); in bcm63xx_udc_data_isr()
2061 req = udc->ep0_request; in bcm63xx_udc_data_isr()
2069 udc->ep0_req_completed = 1; in bcm63xx_udc_data_isr()
2071 schedule_work(&udc->ep0_wq); in bcm63xx_udc_data_isr()
2077 iudma_write(udc, iudma, breq); in bcm63xx_udc_data_isr()
2098 iudma_write(udc, iudma, next); in bcm63xx_udc_data_isr()
2101 iudma_write(udc, iudma, breq); in bcm63xx_udc_data_isr()
2105 spin_unlock(&udc->lock); in bcm63xx_udc_data_isr()
2108 usb_gadget_unmap_request(&udc->gadget, req, iudma->is_tx); in bcm63xx_udc_data_isr()
2129 struct bcm63xx_udc *udc = s->private; in bcm63xx_usbd_dbg_show() local
2131 if (!udc->driver) in bcm63xx_usbd_dbg_show()
2135 bcm63xx_ep0_state_names[udc->ep0state]); in bcm63xx_usbd_dbg_show()
2137 udc->ep0_req_reset ? "reset " : "", in bcm63xx_usbd_dbg_show()
2138 udc->ep0_req_set_cfg ? "set_cfg " : "", in bcm63xx_usbd_dbg_show()
2139 udc->ep0_req_set_iface ? "set_iface " : "", in bcm63xx_usbd_dbg_show()
2140 udc->ep0_req_shutdown ? "shutdown " : "", in bcm63xx_usbd_dbg_show()
2141 udc->ep0_request ? "pending " : "", in bcm63xx_usbd_dbg_show()
2142 udc->ep0_req_completed ? "completed " : "", in bcm63xx_usbd_dbg_show()
2143 udc->ep0_reply ? "reply " : ""); in bcm63xx_usbd_dbg_show()
2145 udc->cfg, udc->iface, udc->alt_iface); in bcm63xx_usbd_dbg_show()
2148 usbd_readl(udc, USBD_CONTROL_REG), in bcm63xx_usbd_dbg_show()
2149 usbd_readl(udc, USBD_STRAPS_REG), in bcm63xx_usbd_dbg_show()
2150 usbd_readl(udc, USBD_STATUS_REG)); in bcm63xx_usbd_dbg_show()
2152 usbd_readl(udc, USBD_EVENTS_REG), in bcm63xx_usbd_dbg_show()
2153 usbd_readl(udc, USBD_STALL_REG)); in bcm63xx_usbd_dbg_show()
2168 struct bcm63xx_udc *udc = s->private; in bcm63xx_iudma_dbg_show() local
2172 if (!udc->driver) in bcm63xx_iudma_dbg_show()
2176 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in bcm63xx_iudma_dbg_show()
2195 usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2196 usb_dmac_readl(udc, ENETDMAC_IR_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2197 usb_dmac_readl(udc, ENETDMAC_IRMASK_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2198 usb_dmac_readl(udc, ENETDMAC_MAXBURST_REG, ch_idx)); in bcm63xx_iudma_dbg_show()
2200 sram2 = usb_dmas_readl(udc, ENETDMAS_SRAM2_REG, ch_idx); in bcm63xx_iudma_dbg_show()
2201 sram3 = usb_dmas_readl(udc, ENETDMAS_SRAM3_REG, ch_idx); in bcm63xx_iudma_dbg_show()
2203 usb_dmas_readl(udc, ENETDMAS_RSTART_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2206 usb_dmas_readl(udc, ENETDMAS_SRAM4_REG, ch_idx)); in bcm63xx_iudma_dbg_show()
2244 static void bcm63xx_udc_init_debugfs(struct bcm63xx_udc *udc) in bcm63xx_udc_init_debugfs() argument
2251 root = debugfs_create_dir(udc->gadget.name, NULL); in bcm63xx_udc_init_debugfs()
2252 udc->debugfs_root = root; in bcm63xx_udc_init_debugfs()
2254 debugfs_create_file("usbd", 0400, root, udc, &bcm63xx_usbd_dbg_fops); in bcm63xx_udc_init_debugfs()
2255 debugfs_create_file("iudma", 0400, root, udc, &bcm63xx_iudma_dbg_fops); in bcm63xx_udc_init_debugfs()
2264 static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc) in bcm63xx_udc_cleanup_debugfs() argument
2266 debugfs_remove_recursive(udc->debugfs_root); in bcm63xx_udc_cleanup_debugfs()
2284 struct bcm63xx_udc *udc; in bcm63xx_udc_probe() local
2288 udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); in bcm63xx_udc_probe()
2289 if (!udc) in bcm63xx_udc_probe()
2292 platform_set_drvdata(pdev, udc); in bcm63xx_udc_probe()
2293 udc->dev = dev; in bcm63xx_udc_probe()
2294 udc->pd = pd; in bcm63xx_udc_probe()
2302 udc->usbd_regs = devm_ioremap_resource(dev, res); in bcm63xx_udc_probe()
2303 if (IS_ERR(udc->usbd_regs)) in bcm63xx_udc_probe()
2304 return PTR_ERR(udc->usbd_regs); in bcm63xx_udc_probe()
2307 udc->iudma_regs = devm_ioremap_resource(dev, res); in bcm63xx_udc_probe()
2308 if (IS_ERR(udc->iudma_regs)) in bcm63xx_udc_probe()
2309 return PTR_ERR(udc->iudma_regs); in bcm63xx_udc_probe()
2311 spin_lock_init(&udc->lock); in bcm63xx_udc_probe()
2312 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process); in bcm63xx_udc_probe()
2314 udc->gadget.ops = &bcm63xx_udc_ops; in bcm63xx_udc_probe()
2315 udc->gadget.name = dev_name(dev); in bcm63xx_udc_probe()
2318 udc->gadget.max_speed = USB_SPEED_HIGH; in bcm63xx_udc_probe()
2320 udc->gadget.max_speed = USB_SPEED_FULL; in bcm63xx_udc_probe()
2323 rc = bcm63xx_init_udc_hw(udc); in bcm63xx_udc_probe()
2336 dev_name(dev), udc) < 0) in bcm63xx_udc_probe()
2347 dev_name(dev), &udc->iudma[i]) < 0) in bcm63xx_udc_probe()
2351 bcm63xx_udc_init_debugfs(udc); in bcm63xx_udc_probe()
2352 rc = usb_add_gadget_udc(dev, &udc->gadget); in bcm63xx_udc_probe()
2356 bcm63xx_udc_cleanup_debugfs(udc); in bcm63xx_udc_probe()
2358 bcm63xx_uninit_udc_hw(udc); in bcm63xx_udc_probe()
2372 struct bcm63xx_udc *udc = platform_get_drvdata(pdev); in bcm63xx_udc_remove() local
2374 bcm63xx_udc_cleanup_debugfs(udc); in bcm63xx_udc_remove()
2375 usb_del_gadget_udc(&udc->gadget); in bcm63xx_udc_remove()
2376 BUG_ON(udc->driver); in bcm63xx_udc_remove()
2378 bcm63xx_uninit_udc_hw(udc); in bcm63xx_udc_remove()