Lines Matching refs:udc

217 	struct bcm63xx_udc		*udc;  member
242 struct bcm63xx_udc *udc; member
352 static inline u32 usbd_readl(struct bcm63xx_udc *udc, u32 off) in usbd_readl() argument
354 return bcm_readl(udc->usbd_regs + off); in usbd_readl()
357 static inline void usbd_writel(struct bcm63xx_udc *udc, u32 val, u32 off) in usbd_writel() argument
359 bcm_writel(val, udc->usbd_regs + off); in usbd_writel()
362 static inline u32 usb_dma_readl(struct bcm63xx_udc *udc, u32 off) in usb_dma_readl() argument
364 return bcm_readl(udc->iudma_regs + off); in usb_dma_readl()
367 static inline void usb_dma_writel(struct bcm63xx_udc *udc, u32 val, u32 off) in usb_dma_writel() argument
369 bcm_writel(val, udc->iudma_regs + off); in usb_dma_writel()
372 static inline u32 usb_dmac_readl(struct bcm63xx_udc *udc, u32 off, int chan) in usb_dmac_readl() argument
374 return bcm_readl(udc->iudma_regs + IUDMA_DMAC_OFFSET + off + in usb_dmac_readl()
378 static inline void usb_dmac_writel(struct bcm63xx_udc *udc, u32 val, u32 off, in usb_dmac_writel() argument
381 bcm_writel(val, udc->iudma_regs + IUDMA_DMAC_OFFSET + off + in usb_dmac_writel()
385 static inline u32 usb_dmas_readl(struct bcm63xx_udc *udc, u32 off, int chan) in usb_dmas_readl() argument
387 return bcm_readl(udc->iudma_regs + IUDMA_DMAS_OFFSET + off + in usb_dmas_readl()
391 static inline void usb_dmas_writel(struct bcm63xx_udc *udc, u32 val, u32 off, in usb_dmas_writel() argument
394 bcm_writel(val, udc->iudma_regs + IUDMA_DMAS_OFFSET + off + in usb_dmas_writel()
398 static inline void set_clocks(struct bcm63xx_udc *udc, bool is_enabled) in set_clocks() argument
401 clk_enable(udc->usbh_clk); in set_clocks()
402 clk_enable(udc->usbd_clk); in set_clocks()
405 clk_disable(udc->usbd_clk); in set_clocks()
406 clk_disable(udc->usbh_clk); in set_clocks()
423 static void bcm63xx_ep_dma_select(struct bcm63xx_udc *udc, int idx) in bcm63xx_ep_dma_select() argument
425 u32 val = usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_ep_dma_select()
429 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_ep_dma_select()
441 static void bcm63xx_set_stall(struct bcm63xx_udc *udc, struct bcm63xx_ep *bep, in bcm63xx_set_stall() argument
449 usbd_writel(udc, val, USBD_STALL_REG); in bcm63xx_set_stall()
459 static void bcm63xx_fifo_setup(struct bcm63xx_udc *udc) in bcm63xx_fifo_setup() argument
461 int is_hs = udc->gadget.speed == USB_SPEED_HIGH; in bcm63xx_fifo_setup()
470 bcm63xx_ep_dma_select(udc, i >> 1); in bcm63xx_fifo_setup()
476 usbd_writel(udc, val, USBD_RXFIFO_CONFIG_REG); in bcm63xx_fifo_setup()
477 usbd_writel(udc, in bcm63xx_fifo_setup()
485 usbd_writel(udc, val, USBD_TXFIFO_CONFIG_REG); in bcm63xx_fifo_setup()
486 usbd_writel(udc, in bcm63xx_fifo_setup()
490 usbd_readl(udc, USBD_TXFIFO_EPSIZE_REG); in bcm63xx_fifo_setup()
499 static void bcm63xx_fifo_reset_ep(struct bcm63xx_udc *udc, int ep_num) in bcm63xx_fifo_reset_ep() argument
503 bcm63xx_ep_dma_select(udc, ep_num); in bcm63xx_fifo_reset_ep()
505 val = usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
507 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
508 usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
515 static void bcm63xx_fifo_reset(struct bcm63xx_udc *udc) in bcm63xx_fifo_reset() argument
520 bcm63xx_fifo_reset_ep(udc, i); in bcm63xx_fifo_reset()
527 static void bcm63xx_ep_init(struct bcm63xx_udc *udc) in bcm63xx_ep_init() argument
537 bcm63xx_ep_dma_select(udc, cfg->ep_num); in bcm63xx_ep_init()
540 usbd_writel(udc, val, USBD_EPNUM_TYPEMAP_REG); in bcm63xx_ep_init()
550 static void bcm63xx_ep_setup(struct bcm63xx_udc *udc) in bcm63xx_ep_setup() argument
554 usbd_writel(udc, USBD_CSR_SETUPADDR_DEF, USBD_CSR_SETUPADDR_REG); in bcm63xx_ep_setup()
558 int max_pkt = udc->gadget.speed == USB_SPEED_HIGH ? in bcm63xx_ep_setup()
562 udc->iudma[i].max_pkt = max_pkt; in bcm63xx_ep_setup()
566 usb_ep_set_maxpacket_limit(&udc->bep[idx].ep, max_pkt); in bcm63xx_ep_setup()
571 (udc->cfg << USBD_CSR_EP_CFG_SHIFT) | in bcm63xx_ep_setup()
572 (udc->iface << USBD_CSR_EP_IFACE_SHIFT) | in bcm63xx_ep_setup()
573 (udc->alt_iface << USBD_CSR_EP_ALTIFACE_SHIFT) | in bcm63xx_ep_setup()
575 usbd_writel(udc, val, USBD_CSR_EP_REG(idx)); in bcm63xx_ep_setup()
592 static void iudma_write(struct bcm63xx_udc *udc, struct iudma_ch *iudma, in iudma_write() argument
655 usb_dmac_writel(udc, ENETDMAC_CHANCFG_EN_MASK, in iudma_write()
668 static int iudma_read(struct bcm63xx_udc *udc, struct iudma_ch *iudma) in iudma_read() argument
702 static void iudma_reset_channel(struct bcm63xx_udc *udc, struct iudma_ch *iudma) in iudma_reset_channel() argument
709 bcm63xx_fifo_reset_ep(udc, max(0, iudma->ep_num)); in iudma_reset_channel()
712 usb_dmac_writel(udc, 0, ENETDMAC_CHANCFG_REG, ch_idx); in iudma_reset_channel()
714 while (usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx) & in iudma_reset_channel()
720 bcm63xx_fifo_reset_ep(udc, iudma->ep_num); in iudma_reset_channel()
723 dev_err(udc->dev, "can't reset IUDMA channel %d\n", in iudma_reset_channel()
728 dev_warn(udc->dev, "forcibly halting IUDMA channel %d\n", in iudma_reset_channel()
730 usb_dmac_writel(udc, ENETDMAC_CHANCFG_BUFHALT_MASK, in iudma_reset_channel()
734 usb_dmac_writel(udc, ~0, ENETDMAC_IR_REG, ch_idx); in iudma_reset_channel()
745 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, in iudma_reset_channel()
747 usb_dmac_writel(udc, 8, ENETDMAC_MAXBURST_REG, ch_idx); in iudma_reset_channel()
749 usb_dmas_writel(udc, iudma->bd_ring_dma, ENETDMAS_RSTART_REG, ch_idx); in iudma_reset_channel()
750 usb_dmas_writel(udc, 0, ENETDMAS_SRAM2_REG, ch_idx); in iudma_reset_channel()
758 static int iudma_init_channel(struct bcm63xx_udc *udc, unsigned int ch_idx) in iudma_init_channel() argument
760 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in iudma_init_channel()
769 bep = &udc->bep[iudma->ep_num]; in iudma_init_channel()
775 iudma->udc = udc; in iudma_init_channel()
782 iudma->bd_ring = dmam_alloc_coherent(udc->dev, in iudma_init_channel()
798 static int iudma_init(struct bcm63xx_udc *udc) in iudma_init() argument
802 usb_dma_writel(udc, ENETDMA_CFG_EN_MASK, ENETDMA_CFG_REG); in iudma_init()
805 rc = iudma_init_channel(udc, i); in iudma_init()
808 iudma_reset_channel(udc, &udc->iudma[i]); in iudma_init()
811 usb_dma_writel(udc, BIT(BCM63XX_NUM_IUDMA)-1, ENETDMA_GLB_IRQMASK_REG); in iudma_init()
821 static void iudma_uninit(struct bcm63xx_udc *udc) in iudma_uninit() argument
825 usb_dma_writel(udc, 0, ENETDMA_GLB_IRQMASK_REG); in iudma_uninit()
828 iudma_reset_channel(udc, &udc->iudma[i]); in iudma_uninit()
830 usb_dma_writel(udc, 0, ENETDMA_CFG_REG); in iudma_uninit()
842 static void bcm63xx_set_ctrl_irqs(struct bcm63xx_udc *udc, bool enable_irqs) in bcm63xx_set_ctrl_irqs() argument
846 usbd_writel(udc, 0, USBD_STATUS_REG); in bcm63xx_set_ctrl_irqs()
853 usbd_writel(udc, enable_irqs ? val : 0, USBD_EVENT_IRQ_MASK_REG); in bcm63xx_set_ctrl_irqs()
854 usbd_writel(udc, val, USBD_EVENT_IRQ_STATUS_REG); in bcm63xx_set_ctrl_irqs()
868 static void bcm63xx_select_phy_mode(struct bcm63xx_udc *udc, bool is_device) in bcm63xx_select_phy_mode() argument
870 u32 val, portmask = BIT(udc->pd->port_no); in bcm63xx_select_phy_mode()
908 static void bcm63xx_select_pullup(struct bcm63xx_udc *udc, bool is_on) in bcm63xx_select_pullup() argument
910 u32 val, portmask = BIT(udc->pd->port_no); in bcm63xx_select_pullup()
927 static void bcm63xx_uninit_udc_hw(struct bcm63xx_udc *udc) in bcm63xx_uninit_udc_hw() argument
929 set_clocks(udc, true); in bcm63xx_uninit_udc_hw()
930 iudma_uninit(udc); in bcm63xx_uninit_udc_hw()
931 set_clocks(udc, false); in bcm63xx_uninit_udc_hw()
933 clk_put(udc->usbd_clk); in bcm63xx_uninit_udc_hw()
934 clk_put(udc->usbh_clk); in bcm63xx_uninit_udc_hw()
941 static int bcm63xx_init_udc_hw(struct bcm63xx_udc *udc) in bcm63xx_init_udc_hw() argument
946 udc->ep0_ctrl_buf = devm_kzalloc(udc->dev, BCM63XX_MAX_CTRL_PKT, in bcm63xx_init_udc_hw()
948 if (!udc->ep0_ctrl_buf) in bcm63xx_init_udc_hw()
951 INIT_LIST_HEAD(&udc->gadget.ep_list); in bcm63xx_init_udc_hw()
953 struct bcm63xx_ep *bep = &udc->bep[i]; in bcm63xx_init_udc_hw()
959 list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list); in bcm63xx_init_udc_hw()
962 bep->udc = udc; in bcm63xx_init_udc_hw()
967 udc->gadget.ep0 = &udc->bep[0].ep; in bcm63xx_init_udc_hw()
968 list_del(&udc->bep[0].ep.ep_list); in bcm63xx_init_udc_hw()
970 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_init_udc_hw()
971 udc->ep0state = EP0_SHUTDOWN; in bcm63xx_init_udc_hw()
973 udc->usbh_clk = clk_get(udc->dev, "usbh"); in bcm63xx_init_udc_hw()
974 if (IS_ERR(udc->usbh_clk)) in bcm63xx_init_udc_hw()
977 udc->usbd_clk = clk_get(udc->dev, "usbd"); in bcm63xx_init_udc_hw()
978 if (IS_ERR(udc->usbd_clk)) { in bcm63xx_init_udc_hw()
979 clk_put(udc->usbh_clk); in bcm63xx_init_udc_hw()
983 set_clocks(udc, true); in bcm63xx_init_udc_hw()
988 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_init_udc_hw()
996 if (udc->gadget.max_speed == USB_SPEED_HIGH) in bcm63xx_init_udc_hw()
1000 usbd_writel(udc, val, USBD_STRAPS_REG); in bcm63xx_init_udc_hw()
1002 bcm63xx_set_ctrl_irqs(udc, false); in bcm63xx_init_udc_hw()
1004 usbd_writel(udc, 0, USBD_EVENT_IRQ_CFG_LO_REG); in bcm63xx_init_udc_hw()
1008 usbd_writel(udc, val, USBD_EVENT_IRQ_CFG_HI_REG); in bcm63xx_init_udc_hw()
1010 rc = iudma_init(udc); in bcm63xx_init_udc_hw()
1011 set_clocks(udc, false); in bcm63xx_init_udc_hw()
1013 bcm63xx_uninit_udc_hw(udc); in bcm63xx_init_udc_hw()
1034 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_ep_enable() local
1041 if (!udc->driver) in bcm63xx_ep_enable()
1044 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_enable()
1046 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_enable()
1053 iudma_reset_channel(udc, iudma); in bcm63xx_ep_enable()
1056 bcm63xx_set_stall(udc, bep, false); in bcm63xx_ep_enable()
1057 clear_bit(bep->ep_num, &udc->wedgemap); in bcm63xx_ep_enable()
1062 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_enable()
1073 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_ep_disable() local
1081 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_disable()
1083 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1088 iudma_reset_channel(udc, iudma); in bcm63xx_ep_disable()
1092 usb_gadget_unmap_request(&udc->gadget, &breq->req, in bcm63xx_ep_disable()
1097 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1099 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_disable()
1104 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1154 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_queue() local
1166 if (bep == &udc->bep[0]) { in bcm63xx_udc_queue()
1168 if (udc->ep0_reply) in bcm63xx_udc_queue()
1171 udc->ep0_reply = req; in bcm63xx_udc_queue()
1172 schedule_work(&udc->ep0_wq); in bcm63xx_udc_queue()
1176 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_queue()
1182 rc = usb_gadget_map_request(&udc->gadget, req, bep->iudma->is_tx); in bcm63xx_udc_queue()
1186 iudma_write(udc, bep->iudma, breq); in bcm63xx_udc_queue()
1190 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_queue()
1206 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_dequeue() local
1211 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_dequeue()
1218 usb_gadget_unmap_request(&udc->gadget, &breq->req, bep->iudma->is_tx); in bcm63xx_udc_dequeue()
1221 iudma_reset_channel(udc, bep->iudma); in bcm63xx_udc_dequeue()
1229 iudma_write(udc, bep->iudma, next); in bcm63xx_udc_dequeue()
1236 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_dequeue()
1254 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_set_halt() local
1257 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_set_halt()
1258 bcm63xx_set_stall(udc, bep, !!value); in bcm63xx_udc_set_halt()
1260 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_set_halt()
1274 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_set_wedge() local
1277 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_set_wedge()
1278 set_bit(bep->ep_num, &udc->wedgemap); in bcm63xx_udc_set_wedge()
1279 bcm63xx_set_stall(udc, bep, true); in bcm63xx_udc_set_wedge()
1280 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_set_wedge()
1308 static int bcm63xx_ep0_setup_callback(struct bcm63xx_udc *udc, in bcm63xx_ep0_setup_callback() argument
1313 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_setup_callback()
1314 rc = udc->driver->setup(&udc->gadget, ctrl); in bcm63xx_ep0_setup_callback()
1315 spin_lock_irq(&udc->lock); in bcm63xx_ep0_setup_callback()
1331 static int bcm63xx_ep0_spoof_set_cfg(struct bcm63xx_udc *udc) in bcm63xx_ep0_spoof_set_cfg() argument
1338 ctrl.wValue = cpu_to_le16(udc->cfg); in bcm63xx_ep0_spoof_set_cfg()
1342 rc = bcm63xx_ep0_setup_callback(udc, &ctrl); in bcm63xx_ep0_spoof_set_cfg()
1344 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_spoof_set_cfg()
1346 udc->cfg); in bcm63xx_ep0_spoof_set_cfg()
1355 static int bcm63xx_ep0_spoof_set_iface(struct bcm63xx_udc *udc) in bcm63xx_ep0_spoof_set_iface() argument
1362 ctrl.wValue = cpu_to_le16(udc->alt_iface); in bcm63xx_ep0_spoof_set_iface()
1363 ctrl.wIndex = cpu_to_le16(udc->iface); in bcm63xx_ep0_spoof_set_iface()
1366 rc = bcm63xx_ep0_setup_callback(udc, &ctrl); in bcm63xx_ep0_spoof_set_iface()
1368 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_spoof_set_iface()
1370 udc->iface, udc->alt_iface); in bcm63xx_ep0_spoof_set_iface()
1381 static void bcm63xx_ep0_map_write(struct bcm63xx_udc *udc, int ch_idx, in bcm63xx_ep0_map_write() argument
1385 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in bcm63xx_ep0_map_write()
1387 BUG_ON(udc->ep0_request); in bcm63xx_ep0_map_write()
1388 udc->ep0_request = req; in bcm63xx_ep0_map_write()
1392 usb_gadget_map_request(&udc->gadget, req, iudma->is_tx); in bcm63xx_ep0_map_write()
1393 iudma_write(udc, iudma, breq); in bcm63xx_ep0_map_write()
1402 static void bcm63xx_ep0_complete(struct bcm63xx_udc *udc, in bcm63xx_ep0_complete() argument
1409 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_complete()
1410 req->complete(&udc->bep[0].ep, req); in bcm63xx_ep0_complete()
1411 spin_lock_irq(&udc->lock); in bcm63xx_ep0_complete()
1421 static void bcm63xx_ep0_nuke_reply(struct bcm63xx_udc *udc, int is_tx) in bcm63xx_ep0_nuke_reply() argument
1423 struct usb_request *req = udc->ep0_reply; in bcm63xx_ep0_nuke_reply()
1425 udc->ep0_reply = NULL; in bcm63xx_ep0_nuke_reply()
1426 usb_gadget_unmap_request(&udc->gadget, req, is_tx); in bcm63xx_ep0_nuke_reply()
1427 if (udc->ep0_request == req) { in bcm63xx_ep0_nuke_reply()
1428 udc->ep0_req_completed = 0; in bcm63xx_ep0_nuke_reply()
1429 udc->ep0_request = NULL; in bcm63xx_ep0_nuke_reply()
1431 bcm63xx_ep0_complete(udc, req, -ESHUTDOWN); in bcm63xx_ep0_nuke_reply()
1439 static int bcm63xx_ep0_read_complete(struct bcm63xx_udc *udc) in bcm63xx_ep0_read_complete() argument
1441 struct usb_request *req = udc->ep0_request; in bcm63xx_ep0_read_complete()
1443 udc->ep0_req_completed = 0; in bcm63xx_ep0_read_complete()
1444 udc->ep0_request = NULL; in bcm63xx_ep0_read_complete()
1458 static void bcm63xx_ep0_internal_request(struct bcm63xx_udc *udc, int ch_idx, in bcm63xx_ep0_internal_request() argument
1461 struct usb_request *req = &udc->ep0_ctrl_req.req; in bcm63xx_ep0_internal_request()
1463 req->buf = udc->ep0_ctrl_buf; in bcm63xx_ep0_internal_request()
1467 bcm63xx_ep0_map_write(udc, ch_idx, req); in bcm63xx_ep0_internal_request()
1478 static enum bcm63xx_ep0_state bcm63xx_ep0_do_setup(struct bcm63xx_udc *udc) in bcm63xx_ep0_do_setup() argument
1481 struct usb_ctrlrequest *ctrl = (void *)udc->ep0_ctrl_buf; in bcm63xx_ep0_do_setup()
1483 rc = bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_do_setup()
1486 dev_err(udc->dev, "missing SETUP packet\n"); in bcm63xx_ep0_do_setup()
1500 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_do_setup()
1506 rc = bcm63xx_ep0_setup_callback(udc, ctrl); in bcm63xx_ep0_do_setup()
1508 bcm63xx_set_stall(udc, &udc->bep[0], true); in bcm63xx_ep0_do_setup()
1531 static int bcm63xx_ep0_do_idle(struct bcm63xx_udc *udc) in bcm63xx_ep0_do_idle() argument
1533 if (udc->ep0_req_reset) { in bcm63xx_ep0_do_idle()
1534 udc->ep0_req_reset = 0; in bcm63xx_ep0_do_idle()
1535 } else if (udc->ep0_req_set_cfg) { in bcm63xx_ep0_do_idle()
1536 udc->ep0_req_set_cfg = 0; in bcm63xx_ep0_do_idle()
1537 if (bcm63xx_ep0_spoof_set_cfg(udc) >= 0) in bcm63xx_ep0_do_idle()
1538 udc->ep0state = EP0_IN_FAKE_STATUS_PHASE; in bcm63xx_ep0_do_idle()
1539 } else if (udc->ep0_req_set_iface) { in bcm63xx_ep0_do_idle()
1540 udc->ep0_req_set_iface = 0; in bcm63xx_ep0_do_idle()
1541 if (bcm63xx_ep0_spoof_set_iface(udc) >= 0) in bcm63xx_ep0_do_idle()
1542 udc->ep0state = EP0_IN_FAKE_STATUS_PHASE; in bcm63xx_ep0_do_idle()
1543 } else if (udc->ep0_req_completed) { in bcm63xx_ep0_do_idle()
1544 udc->ep0state = bcm63xx_ep0_do_setup(udc); in bcm63xx_ep0_do_idle()
1545 return udc->ep0state == EP0_IDLE ? -EAGAIN : 0; in bcm63xx_ep0_do_idle()
1546 } else if (udc->ep0_req_shutdown) { in bcm63xx_ep0_do_idle()
1547 udc->ep0_req_shutdown = 0; in bcm63xx_ep0_do_idle()
1548 udc->ep0_req_completed = 0; in bcm63xx_ep0_do_idle()
1549 udc->ep0_request = NULL; in bcm63xx_ep0_do_idle()
1550 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_RXCHAN]); in bcm63xx_ep0_do_idle()
1551 usb_gadget_unmap_request(&udc->gadget, in bcm63xx_ep0_do_idle()
1552 &udc->ep0_ctrl_req.req, 0); in bcm63xx_ep0_do_idle()
1556 udc->ep0state = EP0_SHUTDOWN; in bcm63xx_ep0_do_idle()
1557 } else if (udc->ep0_reply) { in bcm63xx_ep0_do_idle()
1563 dev_warn(udc->dev, "nuking unexpected reply\n"); in bcm63xx_ep0_do_idle()
1564 bcm63xx_ep0_nuke_reply(udc, 0); in bcm63xx_ep0_do_idle()
1578 static int bcm63xx_ep0_one_round(struct bcm63xx_udc *udc) in bcm63xx_ep0_one_round() argument
1580 enum bcm63xx_ep0_state ep0state = udc->ep0state; in bcm63xx_ep0_one_round()
1581 bool shutdown = udc->ep0_req_reset || udc->ep0_req_shutdown; in bcm63xx_ep0_one_round()
1583 switch (udc->ep0state) { in bcm63xx_ep0_one_round()
1586 bcm63xx_ep0_internal_request(udc, IUDMA_EP0_RXCHAN, in bcm63xx_ep0_one_round()
1591 return bcm63xx_ep0_do_idle(udc); in bcm63xx_ep0_one_round()
1602 if (udc->ep0_reply) { in bcm63xx_ep0_one_round()
1603 bcm63xx_ep0_map_write(udc, IUDMA_EP0_TXCHAN, in bcm63xx_ep0_one_round()
1604 udc->ep0_reply); in bcm63xx_ep0_one_round()
1618 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1619 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1620 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1627 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_TXCHAN]); in bcm63xx_ep0_one_round()
1628 bcm63xx_ep0_nuke_reply(udc, 1); in bcm63xx_ep0_one_round()
1635 if (udc->ep0_reply) { in bcm63xx_ep0_one_round()
1636 bcm63xx_ep0_map_write(udc, IUDMA_EP0_RXCHAN, in bcm63xx_ep0_one_round()
1637 udc->ep0_reply); in bcm63xx_ep0_one_round()
1645 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1646 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1647 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1650 bcm63xx_ep0_internal_request(udc, IUDMA_EP0_TXCHAN, 0); in bcm63xx_ep0_one_round()
1653 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_RXCHAN]); in bcm63xx_ep0_one_round()
1654 bcm63xx_ep0_nuke_reply(udc, 0); in bcm63xx_ep0_one_round()
1668 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1669 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1672 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_TXCHAN]); in bcm63xx_ep0_one_round()
1673 udc->ep0_request = NULL; in bcm63xx_ep0_one_round()
1692 struct usb_request *r = udc->ep0_reply; in bcm63xx_ep0_one_round()
1700 bcm63xx_ep0_complete(udc, r, 0); in bcm63xx_ep0_one_round()
1701 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1709 if (udc->ep0state == ep0state) in bcm63xx_ep0_one_round()
1712 udc->ep0state = ep0state; in bcm63xx_ep0_one_round()
1732 struct bcm63xx_udc *udc = container_of(w, struct bcm63xx_udc, ep0_wq); in bcm63xx_ep0_process() local
1733 spin_lock_irq(&udc->lock); in bcm63xx_ep0_process()
1734 while (bcm63xx_ep0_one_round(udc) == 0) in bcm63xx_ep0_process()
1736 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_process()
1749 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_get_frame() local
1751 return (usbd_readl(udc, USBD_STATUS_REG) & in bcm63xx_udc_get_frame()
1764 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_pullup() local
1768 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_pullup()
1769 if (is_on && udc->ep0state == EP0_SHUTDOWN) { in bcm63xx_udc_pullup()
1770 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_udc_pullup()
1771 udc->ep0state = EP0_REQUEUE; in bcm63xx_udc_pullup()
1772 bcm63xx_fifo_setup(udc); in bcm63xx_udc_pullup()
1773 bcm63xx_fifo_reset(udc); in bcm63xx_udc_pullup()
1774 bcm63xx_ep_setup(udc); in bcm63xx_udc_pullup()
1776 bitmap_zero(&udc->wedgemap, BCM63XX_NUM_EP); in bcm63xx_udc_pullup()
1778 bcm63xx_set_stall(udc, &udc->bep[i], false); in bcm63xx_udc_pullup()
1780 bcm63xx_set_ctrl_irqs(udc, true); in bcm63xx_udc_pullup()
1783 } else if (!is_on && udc->ep0state != EP0_SHUTDOWN) { in bcm63xx_udc_pullup()
1786 udc->ep0_req_shutdown = 1; in bcm63xx_udc_pullup()
1787 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_pullup()
1790 schedule_work(&udc->ep0_wq); in bcm63xx_udc_pullup()
1791 if (udc->ep0state == EP0_SHUTDOWN) in bcm63xx_udc_pullup()
1795 bcm63xx_set_ctrl_irqs(udc, false); in bcm63xx_udc_pullup()
1796 cancel_work_sync(&udc->ep0_wq); in bcm63xx_udc_pullup()
1800 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_pullup()
1812 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_start() local
1818 if (!udc) in bcm63xx_udc_start()
1820 if (udc->driver) in bcm63xx_udc_start()
1823 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_start()
1825 set_clocks(udc, true); in bcm63xx_udc_start()
1826 bcm63xx_fifo_setup(udc); in bcm63xx_udc_start()
1827 bcm63xx_ep_init(udc); in bcm63xx_udc_start()
1828 bcm63xx_ep_setup(udc); in bcm63xx_udc_start()
1829 bcm63xx_fifo_reset(udc); in bcm63xx_udc_start()
1830 bcm63xx_select_phy_mode(udc, true); in bcm63xx_udc_start()
1832 udc->driver = driver; in bcm63xx_udc_start()
1834 udc->gadget.dev.of_node = udc->dev->of_node; in bcm63xx_udc_start()
1836 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_start()
1848 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_stop() local
1851 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_stop()
1853 udc->driver = NULL; in bcm63xx_udc_stop()
1863 bcm63xx_select_phy_mode(udc, false); in bcm63xx_udc_stop()
1864 set_clocks(udc, false); in bcm63xx_udc_stop()
1866 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_stop()
1891 static void bcm63xx_update_cfg_iface(struct bcm63xx_udc *udc) in bcm63xx_update_cfg_iface() argument
1893 u32 reg = usbd_readl(udc, USBD_STATUS_REG); in bcm63xx_update_cfg_iface()
1895 udc->cfg = (reg & USBD_STATUS_CFG_MASK) >> USBD_STATUS_CFG_SHIFT; in bcm63xx_update_cfg_iface()
1896 udc->iface = (reg & USBD_STATUS_INTF_MASK) >> USBD_STATUS_INTF_SHIFT; in bcm63xx_update_cfg_iface()
1897 udc->alt_iface = (reg & USBD_STATUS_ALTINTF_MASK) >> in bcm63xx_update_cfg_iface()
1899 bcm63xx_ep_setup(udc); in bcm63xx_update_cfg_iface()
1909 static int bcm63xx_update_link_speed(struct bcm63xx_udc *udc) in bcm63xx_update_link_speed() argument
1911 u32 reg = usbd_readl(udc, USBD_STATUS_REG); in bcm63xx_update_link_speed()
1912 enum usb_device_speed oldspeed = udc->gadget.speed; in bcm63xx_update_link_speed()
1916 udc->gadget.speed = USB_SPEED_HIGH; in bcm63xx_update_link_speed()
1919 udc->gadget.speed = USB_SPEED_FULL; in bcm63xx_update_link_speed()
1923 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_update_link_speed()
1924 dev_err(udc->dev, in bcm63xx_update_link_speed()
1929 if (udc->gadget.speed != oldspeed) { in bcm63xx_update_link_speed()
1930 dev_info(udc->dev, "link up, %s-speed mode\n", in bcm63xx_update_link_speed()
1931 udc->gadget.speed == USB_SPEED_HIGH ? "high" : "full"); in bcm63xx_update_link_speed()
1949 static void bcm63xx_update_wedge(struct bcm63xx_udc *udc, bool new_status) in bcm63xx_update_wedge() argument
1953 for_each_set_bit(i, &udc->wedgemap, BCM63XX_NUM_EP) { in bcm63xx_update_wedge()
1954 bcm63xx_set_stall(udc, &udc->bep[i], new_status); in bcm63xx_update_wedge()
1956 clear_bit(i, &udc->wedgemap); in bcm63xx_update_wedge()
1970 struct bcm63xx_udc *udc = dev_id; in bcm63xx_udc_ctrl_isr() local
1974 stat = usbd_readl(udc, USBD_EVENT_IRQ_STATUS_REG) & in bcm63xx_udc_ctrl_isr()
1975 usbd_readl(udc, USBD_EVENT_IRQ_MASK_REG); in bcm63xx_udc_ctrl_isr()
1977 usbd_writel(udc, stat, USBD_EVENT_IRQ_STATUS_REG); in bcm63xx_udc_ctrl_isr()
1979 spin_lock(&udc->lock); in bcm63xx_udc_ctrl_isr()
1983 if (!(usbd_readl(udc, USBD_EVENTS_REG) & in bcm63xx_udc_ctrl_isr()
1985 udc->gadget.speed != USB_SPEED_UNKNOWN) in bcm63xx_udc_ctrl_isr()
1986 dev_info(udc->dev, "link down\n"); in bcm63xx_udc_ctrl_isr()
1988 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_udc_ctrl_isr()
1992 bcm63xx_fifo_setup(udc); in bcm63xx_udc_ctrl_isr()
1993 bcm63xx_fifo_reset(udc); in bcm63xx_udc_ctrl_isr()
1994 bcm63xx_ep_setup(udc); in bcm63xx_udc_ctrl_isr()
1996 bcm63xx_update_wedge(udc, false); in bcm63xx_udc_ctrl_isr()
1998 udc->ep0_req_reset = 1; in bcm63xx_udc_ctrl_isr()
1999 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2003 if (bcm63xx_update_link_speed(udc)) { in bcm63xx_udc_ctrl_isr()
2004 bcm63xx_fifo_setup(udc); in bcm63xx_udc_ctrl_isr()
2005 bcm63xx_ep_setup(udc); in bcm63xx_udc_ctrl_isr()
2007 bcm63xx_update_wedge(udc, true); in bcm63xx_udc_ctrl_isr()
2010 bcm63xx_update_cfg_iface(udc); in bcm63xx_udc_ctrl_isr()
2011 udc->ep0_req_set_cfg = 1; in bcm63xx_udc_ctrl_isr()
2012 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2015 bcm63xx_update_cfg_iface(udc); in bcm63xx_udc_ctrl_isr()
2016 udc->ep0_req_set_iface = 1; in bcm63xx_udc_ctrl_isr()
2017 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2019 spin_unlock(&udc->lock); in bcm63xx_udc_ctrl_isr()
2021 if (disconnected && udc->driver) in bcm63xx_udc_ctrl_isr()
2022 udc->driver->disconnect(&udc->gadget); in bcm63xx_udc_ctrl_isr()
2023 else if (bus_reset && udc->driver) in bcm63xx_udc_ctrl_isr()
2024 usb_gadget_udc_reset(&udc->gadget, udc->driver); in bcm63xx_udc_ctrl_isr()
2042 struct bcm63xx_udc *udc = iudma->udc; in bcm63xx_udc_data_isr() local
2049 spin_lock(&udc->lock); in bcm63xx_udc_data_isr()
2051 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, in bcm63xx_udc_data_isr()
2054 rc = iudma_read(udc, iudma); in bcm63xx_udc_data_isr()
2059 req = udc->ep0_request; in bcm63xx_udc_data_isr()
2067 udc->ep0_req_completed = 1; in bcm63xx_udc_data_isr()
2069 schedule_work(&udc->ep0_wq); in bcm63xx_udc_data_isr()
2075 iudma_write(udc, iudma, breq); in bcm63xx_udc_data_isr()
2096 iudma_write(udc, iudma, next); in bcm63xx_udc_data_isr()
2099 iudma_write(udc, iudma, breq); in bcm63xx_udc_data_isr()
2103 spin_unlock(&udc->lock); in bcm63xx_udc_data_isr()
2106 usb_gadget_unmap_request(&udc->gadget, req, iudma->is_tx); in bcm63xx_udc_data_isr()
2127 struct bcm63xx_udc *udc = s->private; in bcm63xx_usbd_dbg_show() local
2129 if (!udc->driver) in bcm63xx_usbd_dbg_show()
2133 bcm63xx_ep0_state_names[udc->ep0state]); in bcm63xx_usbd_dbg_show()
2135 udc->ep0_req_reset ? "reset " : "", in bcm63xx_usbd_dbg_show()
2136 udc->ep0_req_set_cfg ? "set_cfg " : "", in bcm63xx_usbd_dbg_show()
2137 udc->ep0_req_set_iface ? "set_iface " : "", in bcm63xx_usbd_dbg_show()
2138 udc->ep0_req_shutdown ? "shutdown " : "", in bcm63xx_usbd_dbg_show()
2139 udc->ep0_request ? "pending " : "", in bcm63xx_usbd_dbg_show()
2140 udc->ep0_req_completed ? "completed " : "", in bcm63xx_usbd_dbg_show()
2141 udc->ep0_reply ? "reply " : ""); in bcm63xx_usbd_dbg_show()
2143 udc->cfg, udc->iface, udc->alt_iface); in bcm63xx_usbd_dbg_show()
2146 usbd_readl(udc, USBD_CONTROL_REG), in bcm63xx_usbd_dbg_show()
2147 usbd_readl(udc, USBD_STRAPS_REG), in bcm63xx_usbd_dbg_show()
2148 usbd_readl(udc, USBD_STATUS_REG)); in bcm63xx_usbd_dbg_show()
2150 usbd_readl(udc, USBD_EVENTS_REG), in bcm63xx_usbd_dbg_show()
2151 usbd_readl(udc, USBD_STALL_REG)); in bcm63xx_usbd_dbg_show()
2166 struct bcm63xx_udc *udc = s->private; in bcm63xx_iudma_dbg_show() local
2170 if (!udc->driver) in bcm63xx_iudma_dbg_show()
2174 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in bcm63xx_iudma_dbg_show()
2193 usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2194 usb_dmac_readl(udc, ENETDMAC_IR_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2195 usb_dmac_readl(udc, ENETDMAC_IRMASK_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2196 usb_dmac_readl(udc, ENETDMAC_MAXBURST_REG, ch_idx)); in bcm63xx_iudma_dbg_show()
2198 sram2 = usb_dmas_readl(udc, ENETDMAS_SRAM2_REG, ch_idx); in bcm63xx_iudma_dbg_show()
2199 sram3 = usb_dmas_readl(udc, ENETDMAS_SRAM3_REG, ch_idx); in bcm63xx_iudma_dbg_show()
2201 usb_dmas_readl(udc, ENETDMAS_RSTART_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2204 usb_dmas_readl(udc, ENETDMAS_SRAM4_REG, ch_idx)); in bcm63xx_iudma_dbg_show()
2242 static void bcm63xx_udc_init_debugfs(struct bcm63xx_udc *udc) in bcm63xx_udc_init_debugfs() argument
2249 root = debugfs_create_dir(udc->gadget.name, usb_debug_root); in bcm63xx_udc_init_debugfs()
2250 debugfs_create_file("usbd", 0400, root, udc, &bcm63xx_usbd_dbg_fops); in bcm63xx_udc_init_debugfs()
2251 debugfs_create_file("iudma", 0400, root, udc, &bcm63xx_iudma_dbg_fops); in bcm63xx_udc_init_debugfs()
2260 static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc) in bcm63xx_udc_cleanup_debugfs() argument
2262 debugfs_remove(debugfs_lookup(udc->gadget.name, usb_debug_root)); in bcm63xx_udc_cleanup_debugfs()
2280 struct bcm63xx_udc *udc; in bcm63xx_udc_probe() local
2283 udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); in bcm63xx_udc_probe()
2284 if (!udc) in bcm63xx_udc_probe()
2287 platform_set_drvdata(pdev, udc); in bcm63xx_udc_probe()
2288 udc->dev = dev; in bcm63xx_udc_probe()
2289 udc->pd = pd; in bcm63xx_udc_probe()
2296 udc->usbd_regs = devm_platform_ioremap_resource(pdev, 0); in bcm63xx_udc_probe()
2297 if (IS_ERR(udc->usbd_regs)) in bcm63xx_udc_probe()
2298 return PTR_ERR(udc->usbd_regs); in bcm63xx_udc_probe()
2300 udc->iudma_regs = devm_platform_ioremap_resource(pdev, 1); in bcm63xx_udc_probe()
2301 if (IS_ERR(udc->iudma_regs)) in bcm63xx_udc_probe()
2302 return PTR_ERR(udc->iudma_regs); in bcm63xx_udc_probe()
2304 spin_lock_init(&udc->lock); in bcm63xx_udc_probe()
2305 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process); in bcm63xx_udc_probe()
2307 udc->gadget.ops = &bcm63xx_udc_ops; in bcm63xx_udc_probe()
2308 udc->gadget.name = dev_name(dev); in bcm63xx_udc_probe()
2311 udc->gadget.max_speed = USB_SPEED_HIGH; in bcm63xx_udc_probe()
2313 udc->gadget.max_speed = USB_SPEED_FULL; in bcm63xx_udc_probe()
2316 rc = bcm63xx_init_udc_hw(udc); in bcm63xx_udc_probe()
2327 dev_name(dev), udc) < 0) in bcm63xx_udc_probe()
2336 dev_name(dev), &udc->iudma[i]) < 0) in bcm63xx_udc_probe()
2340 bcm63xx_udc_init_debugfs(udc); in bcm63xx_udc_probe()
2341 rc = usb_add_gadget_udc(dev, &udc->gadget); in bcm63xx_udc_probe()
2345 bcm63xx_udc_cleanup_debugfs(udc); in bcm63xx_udc_probe()
2347 bcm63xx_uninit_udc_hw(udc); in bcm63xx_udc_probe()
2361 struct bcm63xx_udc *udc = platform_get_drvdata(pdev); in bcm63xx_udc_remove() local
2363 bcm63xx_udc_cleanup_debugfs(udc); in bcm63xx_udc_remove()
2364 usb_del_gadget_udc(&udc->gadget); in bcm63xx_udc_remove()
2365 BUG_ON(udc->driver); in bcm63xx_udc_remove()
2367 bcm63xx_uninit_udc_hw(udc); in bcm63xx_udc_remove()