Lines Matching full:udc

3  * bcm63xx_udc.c -- BCM63xx UDC high/full speed USB device controller
194 * @udc: Reference to the device controller.
217 struct bcm63xx_udc *udc; member
234 * @udc: Reference to the device controller.
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()
416 * @udc: Reference to the device controller.
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()
434 * @udc: Reference to the device controller.
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()
454 * @udc: Reference to the device controller.
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()
496 * @udc: Reference to the device controller.
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()
513 * @udc: Reference to the device controller.
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()
525 * @udc: Reference to the device controller.
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()
546 * @udc: Reference to the device controller.
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()
581 * @udc: Reference to the device controller.
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()
661 * @udc: Reference to the device controller.
668 static int iudma_read(struct bcm63xx_udc *udc, struct iudma_ch *iudma) in iudma_read() argument
699 * @udc: Reference to the device controller.
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()
755 * @udc: Reference to the device controller.
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()
794 * @udc: Reference to the device controller.
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()
817 * @udc: Reference to the device controller.
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()
839 * @udc: Reference to the device controller.
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()
859 * @udc: Reference to the device controller.
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()
901 * @udc: Reference to the device controller.
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()
922 * @udc: Reference to the device controller.
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()
939 * @udc: Reference to the device controller.
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()
1305 * @udc: Reference to the device controller.
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()
1321 * @udc: Reference to the device controller.
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()
1353 * @udc: Reference to the device controller.
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()
1377 * @udc: Reference to the device controller.
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()
1398 * @udc: Reference to the device controller.
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()
1418 * @udc: Reference to the device controller.
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()
1437 * @udc: Reference to the device controller.
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()
1451 * @udc: Reference to the device controller.
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()
1472 * @udc: Reference to the device controller.
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()
1522 * @udc: Reference to the device controller.
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()
1574 * @udc: Reference to the device controller.
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()
1740 * Standard UDC gadget operations
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()
1833 udc->gadget.dev.of_node = udc->dev->of_node; in bcm63xx_udc_start()
1835 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_start()
1847 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_stop() local
1850 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_stop()
1852 udc->driver = NULL; in bcm63xx_udc_stop()
1862 bcm63xx_select_phy_mode(udc, false); in bcm63xx_udc_stop()
1863 set_clocks(udc, false); in bcm63xx_udc_stop()
1865 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_stop()
1883 * @udc: Reference to the device controller.
1890 static void bcm63xx_update_cfg_iface(struct bcm63xx_udc *udc) in bcm63xx_update_cfg_iface() argument
1892 u32 reg = usbd_readl(udc, USBD_STATUS_REG); in bcm63xx_update_cfg_iface()
1894 udc->cfg = (reg & USBD_STATUS_CFG_MASK) >> USBD_STATUS_CFG_SHIFT; in bcm63xx_update_cfg_iface()
1895 udc->iface = (reg & USBD_STATUS_INTF_MASK) >> USBD_STATUS_INTF_SHIFT; in bcm63xx_update_cfg_iface()
1896 udc->alt_iface = (reg & USBD_STATUS_ALTINTF_MASK) >> in bcm63xx_update_cfg_iface()
1898 bcm63xx_ep_setup(udc); in bcm63xx_update_cfg_iface()
1903 * @udc: Reference to the device controller.
1908 static int bcm63xx_update_link_speed(struct bcm63xx_udc *udc) in bcm63xx_update_link_speed() argument
1910 u32 reg = usbd_readl(udc, USBD_STATUS_REG); in bcm63xx_update_link_speed()
1911 enum usb_device_speed oldspeed = udc->gadget.speed; in bcm63xx_update_link_speed()
1915 udc->gadget.speed = USB_SPEED_HIGH; in bcm63xx_update_link_speed()
1918 udc->gadget.speed = USB_SPEED_FULL; in bcm63xx_update_link_speed()
1922 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_update_link_speed()
1923 dev_err(udc->dev, in bcm63xx_update_link_speed()
1928 if (udc->gadget.speed != oldspeed) { in bcm63xx_update_link_speed()
1929 dev_info(udc->dev, "link up, %s-speed mode\n", in bcm63xx_update_link_speed()
1930 udc->gadget.speed == USB_SPEED_HIGH ? "high" : "full"); in bcm63xx_update_link_speed()
1939 * @udc: Reference to the device controller.
1948 static void bcm63xx_update_wedge(struct bcm63xx_udc *udc, bool new_status) in bcm63xx_update_wedge() argument
1952 for_each_set_bit(i, &udc->wedgemap, BCM63XX_NUM_EP) { in bcm63xx_update_wedge()
1953 bcm63xx_set_stall(udc, &udc->bep[i], new_status); in bcm63xx_update_wedge()
1955 clear_bit(i, &udc->wedgemap); in bcm63xx_update_wedge()
1969 struct bcm63xx_udc *udc = dev_id; in bcm63xx_udc_ctrl_isr() local
1973 stat = usbd_readl(udc, USBD_EVENT_IRQ_STATUS_REG) & in bcm63xx_udc_ctrl_isr()
1974 usbd_readl(udc, USBD_EVENT_IRQ_MASK_REG); in bcm63xx_udc_ctrl_isr()
1976 usbd_writel(udc, stat, USBD_EVENT_IRQ_STATUS_REG); in bcm63xx_udc_ctrl_isr()
1978 spin_lock(&udc->lock); in bcm63xx_udc_ctrl_isr()
1982 if (!(usbd_readl(udc, USBD_EVENTS_REG) & in bcm63xx_udc_ctrl_isr()
1984 udc->gadget.speed != USB_SPEED_UNKNOWN) in bcm63xx_udc_ctrl_isr()
1985 dev_info(udc->dev, "link down\n"); in bcm63xx_udc_ctrl_isr()
1987 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_udc_ctrl_isr()
1991 bcm63xx_fifo_setup(udc); in bcm63xx_udc_ctrl_isr()
1992 bcm63xx_fifo_reset(udc); in bcm63xx_udc_ctrl_isr()
1993 bcm63xx_ep_setup(udc); in bcm63xx_udc_ctrl_isr()
1995 bcm63xx_update_wedge(udc, false); in bcm63xx_udc_ctrl_isr()
1997 udc->ep0_req_reset = 1; in bcm63xx_udc_ctrl_isr()
1998 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2002 if (bcm63xx_update_link_speed(udc)) { in bcm63xx_udc_ctrl_isr()
2003 bcm63xx_fifo_setup(udc); in bcm63xx_udc_ctrl_isr()
2004 bcm63xx_ep_setup(udc); in bcm63xx_udc_ctrl_isr()
2006 bcm63xx_update_wedge(udc, true); in bcm63xx_udc_ctrl_isr()
2009 bcm63xx_update_cfg_iface(udc); in bcm63xx_udc_ctrl_isr()
2010 udc->ep0_req_set_cfg = 1; in bcm63xx_udc_ctrl_isr()
2011 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2014 bcm63xx_update_cfg_iface(udc); in bcm63xx_udc_ctrl_isr()
2015 udc->ep0_req_set_iface = 1; in bcm63xx_udc_ctrl_isr()
2016 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2018 spin_unlock(&udc->lock); in bcm63xx_udc_ctrl_isr()
2020 if (disconnected && udc->driver) in bcm63xx_udc_ctrl_isr()
2021 udc->driver->disconnect(&udc->gadget); in bcm63xx_udc_ctrl_isr()
2022 else if (bus_reset && udc->driver) in bcm63xx_udc_ctrl_isr()
2023 usb_gadget_udc_reset(&udc->gadget, udc->driver); in bcm63xx_udc_ctrl_isr()
2041 struct bcm63xx_udc *udc = iudma->udc; in bcm63xx_udc_data_isr() local
2048 spin_lock(&udc->lock); in bcm63xx_udc_data_isr()
2050 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, in bcm63xx_udc_data_isr()
2053 rc = iudma_read(udc, iudma); in bcm63xx_udc_data_isr()
2058 req = udc->ep0_request; in bcm63xx_udc_data_isr()
2066 udc->ep0_req_completed = 1; in bcm63xx_udc_data_isr()
2068 schedule_work(&udc->ep0_wq); in bcm63xx_udc_data_isr()
2074 iudma_write(udc, iudma, breq); in bcm63xx_udc_data_isr()
2095 iudma_write(udc, iudma, next); in bcm63xx_udc_data_isr()
2098 iudma_write(udc, iudma, breq); in bcm63xx_udc_data_isr()
2102 spin_unlock(&udc->lock); in bcm63xx_udc_data_isr()
2105 usb_gadget_unmap_request(&udc->gadget, req, iudma->is_tx); in bcm63xx_udc_data_isr()
2126 struct bcm63xx_udc *udc = s->private; in bcm63xx_usbd_dbg_show() local
2128 if (!udc->driver) in bcm63xx_usbd_dbg_show()
2132 bcm63xx_ep0_state_names[udc->ep0state]); in bcm63xx_usbd_dbg_show()
2134 udc->ep0_req_reset ? "reset " : "", in bcm63xx_usbd_dbg_show()
2135 udc->ep0_req_set_cfg ? "set_cfg " : "", in bcm63xx_usbd_dbg_show()
2136 udc->ep0_req_set_iface ? "set_iface " : "", in bcm63xx_usbd_dbg_show()
2137 udc->ep0_req_shutdown ? "shutdown " : "", in bcm63xx_usbd_dbg_show()
2138 udc->ep0_request ? "pending " : "", in bcm63xx_usbd_dbg_show()
2139 udc->ep0_req_completed ? "completed " : "", in bcm63xx_usbd_dbg_show()
2140 udc->ep0_reply ? "reply " : ""); in bcm63xx_usbd_dbg_show()
2142 udc->cfg, udc->iface, udc->alt_iface); in bcm63xx_usbd_dbg_show()
2145 usbd_readl(udc, USBD_CONTROL_REG), in bcm63xx_usbd_dbg_show()
2146 usbd_readl(udc, USBD_STRAPS_REG), in bcm63xx_usbd_dbg_show()
2147 usbd_readl(udc, USBD_STATUS_REG)); in bcm63xx_usbd_dbg_show()
2149 usbd_readl(udc, USBD_EVENTS_REG), in bcm63xx_usbd_dbg_show()
2150 usbd_readl(udc, USBD_STALL_REG)); in bcm63xx_usbd_dbg_show()
2165 struct bcm63xx_udc *udc = s->private; in bcm63xx_iudma_dbg_show() local
2169 if (!udc->driver) in bcm63xx_iudma_dbg_show()
2173 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in bcm63xx_iudma_dbg_show()
2191 usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2192 usb_dmac_readl(udc, ENETDMAC_IR_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2193 usb_dmac_readl(udc, ENETDMAC_IRMASK_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2194 usb_dmac_readl(udc, ENETDMAC_MAXBURST_REG, ch_idx)); in bcm63xx_iudma_dbg_show()
2196 sram2 = usb_dmas_readl(udc, ENETDMAS_SRAM2_REG, ch_idx); in bcm63xx_iudma_dbg_show()
2197 sram3 = usb_dmas_readl(udc, ENETDMAS_SRAM3_REG, ch_idx); in bcm63xx_iudma_dbg_show()
2199 usb_dmas_readl(udc, ENETDMAS_RSTART_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2202 usb_dmas_readl(udc, ENETDMAS_SRAM4_REG, ch_idx)); in bcm63xx_iudma_dbg_show()
2234 * @udc: Reference to the device controller.
2236 static void bcm63xx_udc_init_debugfs(struct bcm63xx_udc *udc) in bcm63xx_udc_init_debugfs() argument
2243 root = debugfs_create_dir(udc->gadget.name, usb_debug_root); in bcm63xx_udc_init_debugfs()
2244 debugfs_create_file("usbd", 0400, root, udc, &bcm63xx_usbd_dbg_fops); in bcm63xx_udc_init_debugfs()
2245 debugfs_create_file("iudma", 0400, root, udc, &bcm63xx_iudma_dbg_fops); in bcm63xx_udc_init_debugfs()
2250 * @udc: Reference to the device controller.
2254 static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc) in bcm63xx_udc_cleanup_debugfs() argument
2256 debugfs_lookup_and_remove(udc->gadget.name, usb_debug_root); in bcm63xx_udc_cleanup_debugfs()
2264 * bcm63xx_udc_probe - Initialize a new instance of the UDC.
2274 struct bcm63xx_udc *udc; in bcm63xx_udc_probe() local
2277 udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); in bcm63xx_udc_probe()
2278 if (!udc) in bcm63xx_udc_probe()
2281 platform_set_drvdata(pdev, udc); in bcm63xx_udc_probe()
2282 udc->dev = dev; in bcm63xx_udc_probe()
2283 udc->pd = pd; in bcm63xx_udc_probe()
2290 udc->usbd_regs = devm_platform_ioremap_resource(pdev, 0); in bcm63xx_udc_probe()
2291 if (IS_ERR(udc->usbd_regs)) in bcm63xx_udc_probe()
2292 return PTR_ERR(udc->usbd_regs); in bcm63xx_udc_probe()
2294 udc->iudma_regs = devm_platform_ioremap_resource(pdev, 1); in bcm63xx_udc_probe()
2295 if (IS_ERR(udc->iudma_regs)) in bcm63xx_udc_probe()
2296 return PTR_ERR(udc->iudma_regs); in bcm63xx_udc_probe()
2298 spin_lock_init(&udc->lock); in bcm63xx_udc_probe()
2299 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process); in bcm63xx_udc_probe()
2301 udc->gadget.ops = &bcm63xx_udc_ops; in bcm63xx_udc_probe()
2302 udc->gadget.name = dev_name(dev); in bcm63xx_udc_probe()
2305 udc->gadget.max_speed = USB_SPEED_HIGH; in bcm63xx_udc_probe()
2307 udc->gadget.max_speed = USB_SPEED_FULL; in bcm63xx_udc_probe()
2310 rc = bcm63xx_init_udc_hw(udc); in bcm63xx_udc_probe()
2323 dev_name(dev), udc) < 0) in bcm63xx_udc_probe()
2334 dev_name(dev), &udc->iudma[i]) < 0) in bcm63xx_udc_probe()
2338 bcm63xx_udc_init_debugfs(udc); in bcm63xx_udc_probe()
2339 rc = usb_add_gadget_udc(dev, &udc->gadget); in bcm63xx_udc_probe()
2343 bcm63xx_udc_cleanup_debugfs(udc); in bcm63xx_udc_probe()
2345 bcm63xx_uninit_udc_hw(udc); in bcm63xx_udc_probe()
2359 struct bcm63xx_udc *udc = platform_get_drvdata(pdev); in bcm63xx_udc_remove() local
2361 bcm63xx_udc_cleanup_debugfs(udc); in bcm63xx_udc_remove()
2362 usb_del_gadget_udc(&udc->gadget); in bcm63xx_udc_remove()
2363 BUG_ON(udc->driver); in bcm63xx_udc_remove()
2365 bcm63xx_uninit_udc_hw(udc); in bcm63xx_udc_remove()