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
355 static inline u32 usbd_readl(struct bcm63xx_udc *udc, u32 off) in usbd_readl() argument
357 return bcm_readl(udc->usbd_regs + off); in usbd_readl()
360 static inline void usbd_writel(struct bcm63xx_udc *udc, u32 val, u32 off) in usbd_writel() argument
362 bcm_writel(val, udc->usbd_regs + off); in usbd_writel()
365 static inline u32 usb_dma_readl(struct bcm63xx_udc *udc, u32 off) in usb_dma_readl() argument
367 return bcm_readl(udc->iudma_regs + off); in usb_dma_readl()
370 static inline void usb_dma_writel(struct bcm63xx_udc *udc, u32 val, u32 off) in usb_dma_writel() argument
372 bcm_writel(val, udc->iudma_regs + off); in usb_dma_writel()
375 static inline u32 usb_dmac_readl(struct bcm63xx_udc *udc, u32 off, int chan) in usb_dmac_readl() argument
377 return bcm_readl(udc->iudma_regs + IUDMA_DMAC_OFFSET + off + in usb_dmac_readl()
381 static inline void usb_dmac_writel(struct bcm63xx_udc *udc, u32 val, u32 off, in usb_dmac_writel() argument
384 bcm_writel(val, udc->iudma_regs + IUDMA_DMAC_OFFSET + off + in usb_dmac_writel()
388 static inline u32 usb_dmas_readl(struct bcm63xx_udc *udc, u32 off, int chan) in usb_dmas_readl() argument
390 return bcm_readl(udc->iudma_regs + IUDMA_DMAS_OFFSET + off + in usb_dmas_readl()
394 static inline void usb_dmas_writel(struct bcm63xx_udc *udc, u32 val, u32 off, in usb_dmas_writel() argument
397 bcm_writel(val, udc->iudma_regs + IUDMA_DMAS_OFFSET + off + in usb_dmas_writel()
401 static inline void set_clocks(struct bcm63xx_udc *udc, bool is_enabled) in set_clocks() argument
404 clk_enable(udc->usbh_clk); in set_clocks()
405 clk_enable(udc->usbd_clk); in set_clocks()
408 clk_disable(udc->usbd_clk); in set_clocks()
409 clk_disable(udc->usbh_clk); in set_clocks()
419 * @udc: Reference to the device controller.
426 static void bcm63xx_ep_dma_select(struct bcm63xx_udc *udc, int idx) in bcm63xx_ep_dma_select() argument
428 u32 val = usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_ep_dma_select()
432 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_ep_dma_select()
437 * @udc: Reference to the device controller.
444 static void bcm63xx_set_stall(struct bcm63xx_udc *udc, struct bcm63xx_ep *bep, in bcm63xx_set_stall() argument
452 usbd_writel(udc, val, USBD_STALL_REG); in bcm63xx_set_stall()
457 * @udc: Reference to the device controller.
462 static void bcm63xx_fifo_setup(struct bcm63xx_udc *udc) in bcm63xx_fifo_setup() argument
464 int is_hs = udc->gadget.speed == USB_SPEED_HIGH; in bcm63xx_fifo_setup()
473 bcm63xx_ep_dma_select(udc, i >> 1); in bcm63xx_fifo_setup()
479 usbd_writel(udc, val, USBD_RXFIFO_CONFIG_REG); in bcm63xx_fifo_setup()
480 usbd_writel(udc, in bcm63xx_fifo_setup()
488 usbd_writel(udc, val, USBD_TXFIFO_CONFIG_REG); in bcm63xx_fifo_setup()
489 usbd_writel(udc, in bcm63xx_fifo_setup()
493 usbd_readl(udc, USBD_TXFIFO_EPSIZE_REG); in bcm63xx_fifo_setup()
499 * @udc: Reference to the device controller.
502 static void bcm63xx_fifo_reset_ep(struct bcm63xx_udc *udc, int ep_num) in bcm63xx_fifo_reset_ep() argument
506 bcm63xx_ep_dma_select(udc, ep_num); in bcm63xx_fifo_reset_ep()
508 val = usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
510 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
511 usbd_readl(udc, USBD_CONTROL_REG); in bcm63xx_fifo_reset_ep()
516 * @udc: Reference to the device controller.
518 static void bcm63xx_fifo_reset(struct bcm63xx_udc *udc) in bcm63xx_fifo_reset() argument
523 bcm63xx_fifo_reset_ep(udc, i); in bcm63xx_fifo_reset()
528 * @udc: Reference to the device controller.
530 static void bcm63xx_ep_init(struct bcm63xx_udc *udc) in bcm63xx_ep_init() argument
540 bcm63xx_ep_dma_select(udc, cfg->ep_num); in bcm63xx_ep_init()
543 usbd_writel(udc, val, USBD_EPNUM_TYPEMAP_REG); in bcm63xx_ep_init()
549 * @udc: Reference to the device controller.
553 static void bcm63xx_ep_setup(struct bcm63xx_udc *udc) in bcm63xx_ep_setup() argument
557 usbd_writel(udc, USBD_CSR_SETUPADDR_DEF, USBD_CSR_SETUPADDR_REG); in bcm63xx_ep_setup()
561 int max_pkt = udc->gadget.speed == USB_SPEED_HIGH ? in bcm63xx_ep_setup()
565 udc->iudma[i].max_pkt = max_pkt; in bcm63xx_ep_setup()
569 usb_ep_set_maxpacket_limit(&udc->bep[idx].ep, max_pkt); in bcm63xx_ep_setup()
574 (udc->cfg << USBD_CSR_EP_CFG_SHIFT) | in bcm63xx_ep_setup()
575 (udc->iface << USBD_CSR_EP_IFACE_SHIFT) | in bcm63xx_ep_setup()
576 (udc->alt_iface << USBD_CSR_EP_ALTIFACE_SHIFT) | in bcm63xx_ep_setup()
578 usbd_writel(udc, val, USBD_CSR_EP_REG(idx)); in bcm63xx_ep_setup()
584 * @udc: Reference to the device controller.
595 static void iudma_write(struct bcm63xx_udc *udc, struct iudma_ch *iudma, in iudma_write() argument
658 usb_dmac_writel(udc, ENETDMAC_CHANCFG_EN_MASK, in iudma_write()
664 * @udc: Reference to the device controller.
671 static int iudma_read(struct bcm63xx_udc *udc, struct iudma_ch *iudma) in iudma_read() argument
702 * @udc: Reference to the device controller.
705 static void iudma_reset_channel(struct bcm63xx_udc *udc, struct iudma_ch *iudma) in iudma_reset_channel() argument
712 bcm63xx_fifo_reset_ep(udc, max(0, iudma->ep_num)); in iudma_reset_channel()
715 usb_dmac_writel(udc, 0, ENETDMAC_CHANCFG_REG, ch_idx); in iudma_reset_channel()
717 while (usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx) & in iudma_reset_channel()
723 bcm63xx_fifo_reset_ep(udc, iudma->ep_num); in iudma_reset_channel()
726 dev_err(udc->dev, "can't reset IUDMA channel %d\n", in iudma_reset_channel()
731 dev_warn(udc->dev, "forcibly halting IUDMA channel %d\n", in iudma_reset_channel()
733 usb_dmac_writel(udc, ENETDMAC_CHANCFG_BUFHALT_MASK, in iudma_reset_channel()
737 usb_dmac_writel(udc, ~0, ENETDMAC_IR_REG, ch_idx); in iudma_reset_channel()
748 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, in iudma_reset_channel()
750 usb_dmac_writel(udc, 8, ENETDMAC_MAXBURST_REG, ch_idx); in iudma_reset_channel()
752 usb_dmas_writel(udc, iudma->bd_ring_dma, ENETDMAS_RSTART_REG, ch_idx); in iudma_reset_channel()
753 usb_dmas_writel(udc, 0, ENETDMAS_SRAM2_REG, ch_idx); in iudma_reset_channel()
758 * @udc: Reference to the device controller.
761 static int iudma_init_channel(struct bcm63xx_udc *udc, unsigned int ch_idx) in iudma_init_channel() argument
763 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in iudma_init_channel()
772 bep = &udc->bep[iudma->ep_num]; in iudma_init_channel()
778 iudma->udc = udc; in iudma_init_channel()
785 iudma->bd_ring = dmam_alloc_coherent(udc->dev, in iudma_init_channel()
797 * @udc: Reference to the device controller.
801 static int iudma_init(struct bcm63xx_udc *udc) in iudma_init() argument
805 usb_dma_writel(udc, ENETDMA_CFG_EN_MASK, ENETDMA_CFG_REG); in iudma_init()
808 rc = iudma_init_channel(udc, i); in iudma_init()
811 iudma_reset_channel(udc, &udc->iudma[i]); in iudma_init()
814 usb_dma_writel(udc, BIT(BCM63XX_NUM_IUDMA)-1, ENETDMA_GLB_IRQMASK_REG); in iudma_init()
820 * @udc: Reference to the device controller.
824 static void iudma_uninit(struct bcm63xx_udc *udc) in iudma_uninit() argument
828 usb_dma_writel(udc, 0, ENETDMA_GLB_IRQMASK_REG); in iudma_uninit()
831 iudma_reset_channel(udc, &udc->iudma[i]); in iudma_uninit()
833 usb_dma_writel(udc, 0, ENETDMA_CFG_REG); in iudma_uninit()
842 * @udc: Reference to the device controller.
845 static void bcm63xx_set_ctrl_irqs(struct bcm63xx_udc *udc, bool enable_irqs) in bcm63xx_set_ctrl_irqs() argument
849 usbd_writel(udc, 0, USBD_STATUS_REG); in bcm63xx_set_ctrl_irqs()
856 usbd_writel(udc, enable_irqs ? val : 0, USBD_EVENT_IRQ_MASK_REG); in bcm63xx_set_ctrl_irqs()
857 usbd_writel(udc, val, USBD_EVENT_IRQ_STATUS_REG); in bcm63xx_set_ctrl_irqs()
862 * @udc: Reference to the device controller.
871 static void bcm63xx_select_phy_mode(struct bcm63xx_udc *udc, bool is_device) in bcm63xx_select_phy_mode() argument
873 u32 val, portmask = BIT(udc->pd->port_no); in bcm63xx_select_phy_mode()
904 * @udc: Reference to the device controller.
911 static void bcm63xx_select_pullup(struct bcm63xx_udc *udc, bool is_on) in bcm63xx_select_pullup() argument
913 u32 val, portmask = BIT(udc->pd->port_no); in bcm63xx_select_pullup()
925 * @udc: Reference to the device controller.
930 static void bcm63xx_uninit_udc_hw(struct bcm63xx_udc *udc) in bcm63xx_uninit_udc_hw() argument
932 set_clocks(udc, true); in bcm63xx_uninit_udc_hw()
933 iudma_uninit(udc); in bcm63xx_uninit_udc_hw()
934 set_clocks(udc, false); in bcm63xx_uninit_udc_hw()
936 clk_put(udc->usbd_clk); in bcm63xx_uninit_udc_hw()
937 clk_put(udc->usbh_clk); in bcm63xx_uninit_udc_hw()
942 * @udc: Reference to the device controller.
944 static int bcm63xx_init_udc_hw(struct bcm63xx_udc *udc) in bcm63xx_init_udc_hw() argument
949 udc->ep0_ctrl_buf = devm_kzalloc(udc->dev, BCM63XX_MAX_CTRL_PKT, in bcm63xx_init_udc_hw()
951 if (!udc->ep0_ctrl_buf) in bcm63xx_init_udc_hw()
954 INIT_LIST_HEAD(&udc->gadget.ep_list); in bcm63xx_init_udc_hw()
956 struct bcm63xx_ep *bep = &udc->bep[i]; in bcm63xx_init_udc_hw()
962 list_add_tail(&bep->ep.ep_list, &udc->gadget.ep_list); in bcm63xx_init_udc_hw()
965 bep->udc = udc; in bcm63xx_init_udc_hw()
970 udc->gadget.ep0 = &udc->bep[0].ep; in bcm63xx_init_udc_hw()
971 list_del(&udc->bep[0].ep.ep_list); in bcm63xx_init_udc_hw()
973 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_init_udc_hw()
974 udc->ep0state = EP0_SHUTDOWN; in bcm63xx_init_udc_hw()
976 udc->usbh_clk = clk_get(udc->dev, "usbh"); in bcm63xx_init_udc_hw()
977 if (IS_ERR(udc->usbh_clk)) in bcm63xx_init_udc_hw()
980 udc->usbd_clk = clk_get(udc->dev, "usbd"); in bcm63xx_init_udc_hw()
981 if (IS_ERR(udc->usbd_clk)) { in bcm63xx_init_udc_hw()
982 clk_put(udc->usbh_clk); in bcm63xx_init_udc_hw()
986 set_clocks(udc, true); in bcm63xx_init_udc_hw()
991 usbd_writel(udc, val, USBD_CONTROL_REG); in bcm63xx_init_udc_hw()
999 if (udc->gadget.max_speed == USB_SPEED_HIGH) in bcm63xx_init_udc_hw()
1003 usbd_writel(udc, val, USBD_STRAPS_REG); in bcm63xx_init_udc_hw()
1005 bcm63xx_set_ctrl_irqs(udc, false); in bcm63xx_init_udc_hw()
1007 usbd_writel(udc, 0, USBD_EVENT_IRQ_CFG_LO_REG); in bcm63xx_init_udc_hw()
1011 usbd_writel(udc, val, USBD_EVENT_IRQ_CFG_HI_REG); in bcm63xx_init_udc_hw()
1013 rc = iudma_init(udc); in bcm63xx_init_udc_hw()
1014 set_clocks(udc, false); in bcm63xx_init_udc_hw()
1016 bcm63xx_uninit_udc_hw(udc); in bcm63xx_init_udc_hw()
1037 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_ep_enable() local
1044 if (!udc->driver) in bcm63xx_ep_enable()
1047 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_enable()
1049 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_enable()
1056 iudma_reset_channel(udc, iudma); in bcm63xx_ep_enable()
1059 bcm63xx_set_stall(udc, bep, false); in bcm63xx_ep_enable()
1060 clear_bit(bep->ep_num, &udc->wedgemap); in bcm63xx_ep_enable()
1065 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_enable()
1076 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_ep_disable() local
1084 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_disable()
1086 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1091 iudma_reset_channel(udc, iudma); in bcm63xx_ep_disable()
1095 usb_gadget_unmap_request(&udc->gadget, &breq->req, in bcm63xx_ep_disable()
1100 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1102 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_ep_disable()
1107 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_ep_disable()
1157 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_queue() local
1169 if (bep == &udc->bep[0]) { in bcm63xx_udc_queue()
1171 if (udc->ep0_reply) in bcm63xx_udc_queue()
1174 udc->ep0_reply = req; in bcm63xx_udc_queue()
1175 schedule_work(&udc->ep0_wq); in bcm63xx_udc_queue()
1179 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_queue()
1185 rc = usb_gadget_map_request(&udc->gadget, req, bep->iudma->is_tx); in bcm63xx_udc_queue()
1189 iudma_write(udc, bep->iudma, breq); in bcm63xx_udc_queue()
1193 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_queue()
1209 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_dequeue() local
1214 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_dequeue()
1221 usb_gadget_unmap_request(&udc->gadget, &breq->req, bep->iudma->is_tx); in bcm63xx_udc_dequeue()
1224 iudma_reset_channel(udc, bep->iudma); in bcm63xx_udc_dequeue()
1232 iudma_write(udc, bep->iudma, next); in bcm63xx_udc_dequeue()
1239 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_dequeue()
1257 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_set_halt() local
1260 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_set_halt()
1261 bcm63xx_set_stall(udc, bep, !!value); in bcm63xx_udc_set_halt()
1263 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_set_halt()
1277 struct bcm63xx_udc *udc = bep->udc; in bcm63xx_udc_set_wedge() local
1280 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_set_wedge()
1281 set_bit(bep->ep_num, &udc->wedgemap); in bcm63xx_udc_set_wedge()
1282 bcm63xx_set_stall(udc, bep, true); in bcm63xx_udc_set_wedge()
1283 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_set_wedge()
1308 * @udc: Reference to the device controller.
1311 static int bcm63xx_ep0_setup_callback(struct bcm63xx_udc *udc, in bcm63xx_ep0_setup_callback() argument
1316 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_setup_callback()
1317 rc = udc->driver->setup(&udc->gadget, ctrl); in bcm63xx_ep0_setup_callback()
1318 spin_lock_irq(&udc->lock); in bcm63xx_ep0_setup_callback()
1324 * @udc: Reference to the device controller.
1334 static int bcm63xx_ep0_spoof_set_cfg(struct bcm63xx_udc *udc) in bcm63xx_ep0_spoof_set_cfg() argument
1341 ctrl.wValue = cpu_to_le16(udc->cfg); in bcm63xx_ep0_spoof_set_cfg()
1345 rc = bcm63xx_ep0_setup_callback(udc, &ctrl); in bcm63xx_ep0_spoof_set_cfg()
1347 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_spoof_set_cfg()
1349 udc->cfg); in bcm63xx_ep0_spoof_set_cfg()
1356 * @udc: Reference to the device controller.
1358 static int bcm63xx_ep0_spoof_set_iface(struct bcm63xx_udc *udc) in bcm63xx_ep0_spoof_set_iface() argument
1365 ctrl.wValue = cpu_to_le16(udc->alt_iface); in bcm63xx_ep0_spoof_set_iface()
1366 ctrl.wIndex = cpu_to_le16(udc->iface); in bcm63xx_ep0_spoof_set_iface()
1369 rc = bcm63xx_ep0_setup_callback(udc, &ctrl); in bcm63xx_ep0_spoof_set_iface()
1371 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_spoof_set_iface()
1373 udc->iface, udc->alt_iface); in bcm63xx_ep0_spoof_set_iface()
1380 * @udc: Reference to the device controller.
1384 static void bcm63xx_ep0_map_write(struct bcm63xx_udc *udc, int ch_idx, in bcm63xx_ep0_map_write() argument
1388 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in bcm63xx_ep0_map_write()
1390 BUG_ON(udc->ep0_request); in bcm63xx_ep0_map_write()
1391 udc->ep0_request = req; in bcm63xx_ep0_map_write()
1395 usb_gadget_map_request(&udc->gadget, req, iudma->is_tx); in bcm63xx_ep0_map_write()
1396 iudma_write(udc, iudma, breq); in bcm63xx_ep0_map_write()
1401 * @udc: Reference to the device controller.
1405 static void bcm63xx_ep0_complete(struct bcm63xx_udc *udc, in bcm63xx_ep0_complete() argument
1412 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_complete()
1413 req->complete(&udc->bep[0].ep, req); in bcm63xx_ep0_complete()
1414 spin_lock_irq(&udc->lock); in bcm63xx_ep0_complete()
1421 * @udc: Reference to the device controller.
1424 static void bcm63xx_ep0_nuke_reply(struct bcm63xx_udc *udc, int is_tx) in bcm63xx_ep0_nuke_reply() argument
1426 struct usb_request *req = udc->ep0_reply; in bcm63xx_ep0_nuke_reply()
1428 udc->ep0_reply = NULL; in bcm63xx_ep0_nuke_reply()
1429 usb_gadget_unmap_request(&udc->gadget, req, is_tx); in bcm63xx_ep0_nuke_reply()
1430 if (udc->ep0_request == req) { in bcm63xx_ep0_nuke_reply()
1431 udc->ep0_req_completed = 0; in bcm63xx_ep0_nuke_reply()
1432 udc->ep0_request = NULL; in bcm63xx_ep0_nuke_reply()
1434 bcm63xx_ep0_complete(udc, req, -ESHUTDOWN); in bcm63xx_ep0_nuke_reply()
1440 * @udc: Reference to the device controller.
1442 static int bcm63xx_ep0_read_complete(struct bcm63xx_udc *udc) in bcm63xx_ep0_read_complete() argument
1444 struct usb_request *req = udc->ep0_request; in bcm63xx_ep0_read_complete()
1446 udc->ep0_req_completed = 0; in bcm63xx_ep0_read_complete()
1447 udc->ep0_request = NULL; in bcm63xx_ep0_read_complete()
1454 * @udc: Reference to the device controller.
1461 static void bcm63xx_ep0_internal_request(struct bcm63xx_udc *udc, int ch_idx, in bcm63xx_ep0_internal_request() argument
1464 struct usb_request *req = &udc->ep0_ctrl_req.req; in bcm63xx_ep0_internal_request()
1466 req->buf = udc->ep0_ctrl_buf; in bcm63xx_ep0_internal_request()
1470 bcm63xx_ep0_map_write(udc, ch_idx, req); in bcm63xx_ep0_internal_request()
1475 * @udc: Reference to the device controller.
1481 static enum bcm63xx_ep0_state bcm63xx_ep0_do_setup(struct bcm63xx_udc *udc) in bcm63xx_ep0_do_setup() argument
1484 struct usb_ctrlrequest *ctrl = (void *)udc->ep0_ctrl_buf; in bcm63xx_ep0_do_setup()
1486 rc = bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_do_setup()
1489 dev_err(udc->dev, "missing SETUP packet\n"); in bcm63xx_ep0_do_setup()
1503 dev_warn_ratelimited(udc->dev, in bcm63xx_ep0_do_setup()
1509 rc = bcm63xx_ep0_setup_callback(udc, ctrl); in bcm63xx_ep0_do_setup()
1511 bcm63xx_set_stall(udc, &udc->bep[0], true); in bcm63xx_ep0_do_setup()
1525 * @udc: Reference to the device controller.
1534 static int bcm63xx_ep0_do_idle(struct bcm63xx_udc *udc) in bcm63xx_ep0_do_idle() argument
1536 if (udc->ep0_req_reset) { in bcm63xx_ep0_do_idle()
1537 udc->ep0_req_reset = 0; in bcm63xx_ep0_do_idle()
1538 } else if (udc->ep0_req_set_cfg) { in bcm63xx_ep0_do_idle()
1539 udc->ep0_req_set_cfg = 0; in bcm63xx_ep0_do_idle()
1540 if (bcm63xx_ep0_spoof_set_cfg(udc) >= 0) in bcm63xx_ep0_do_idle()
1541 udc->ep0state = EP0_IN_FAKE_STATUS_PHASE; in bcm63xx_ep0_do_idle()
1542 } else if (udc->ep0_req_set_iface) { in bcm63xx_ep0_do_idle()
1543 udc->ep0_req_set_iface = 0; in bcm63xx_ep0_do_idle()
1544 if (bcm63xx_ep0_spoof_set_iface(udc) >= 0) in bcm63xx_ep0_do_idle()
1545 udc->ep0state = EP0_IN_FAKE_STATUS_PHASE; in bcm63xx_ep0_do_idle()
1546 } else if (udc->ep0_req_completed) { in bcm63xx_ep0_do_idle()
1547 udc->ep0state = bcm63xx_ep0_do_setup(udc); in bcm63xx_ep0_do_idle()
1548 return udc->ep0state == EP0_IDLE ? -EAGAIN : 0; in bcm63xx_ep0_do_idle()
1549 } else if (udc->ep0_req_shutdown) { in bcm63xx_ep0_do_idle()
1550 udc->ep0_req_shutdown = 0; in bcm63xx_ep0_do_idle()
1551 udc->ep0_req_completed = 0; in bcm63xx_ep0_do_idle()
1552 udc->ep0_request = NULL; in bcm63xx_ep0_do_idle()
1553 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_RXCHAN]); in bcm63xx_ep0_do_idle()
1554 usb_gadget_unmap_request(&udc->gadget, in bcm63xx_ep0_do_idle()
1555 &udc->ep0_ctrl_req.req, 0); in bcm63xx_ep0_do_idle()
1559 udc->ep0state = EP0_SHUTDOWN; in bcm63xx_ep0_do_idle()
1560 } else if (udc->ep0_reply) { in bcm63xx_ep0_do_idle()
1566 dev_warn(udc->dev, "nuking unexpected reply\n"); in bcm63xx_ep0_do_idle()
1567 bcm63xx_ep0_nuke_reply(udc, 0); in bcm63xx_ep0_do_idle()
1577 * @udc: Reference to the device controller.
1581 static int bcm63xx_ep0_one_round(struct bcm63xx_udc *udc) in bcm63xx_ep0_one_round() argument
1583 enum bcm63xx_ep0_state ep0state = udc->ep0state; in bcm63xx_ep0_one_round()
1584 bool shutdown = udc->ep0_req_reset || udc->ep0_req_shutdown; in bcm63xx_ep0_one_round()
1586 switch (udc->ep0state) { in bcm63xx_ep0_one_round()
1589 bcm63xx_ep0_internal_request(udc, IUDMA_EP0_RXCHAN, in bcm63xx_ep0_one_round()
1594 return bcm63xx_ep0_do_idle(udc); in bcm63xx_ep0_one_round()
1605 if (udc->ep0_reply) { in bcm63xx_ep0_one_round()
1606 bcm63xx_ep0_map_write(udc, IUDMA_EP0_TXCHAN, in bcm63xx_ep0_one_round()
1607 udc->ep0_reply); in bcm63xx_ep0_one_round()
1621 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1622 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1623 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1630 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_TXCHAN]); in bcm63xx_ep0_one_round()
1631 bcm63xx_ep0_nuke_reply(udc, 1); in bcm63xx_ep0_one_round()
1638 if (udc->ep0_reply) { in bcm63xx_ep0_one_round()
1639 bcm63xx_ep0_map_write(udc, IUDMA_EP0_RXCHAN, in bcm63xx_ep0_one_round()
1640 udc->ep0_reply); in bcm63xx_ep0_one_round()
1648 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1649 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1650 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1653 bcm63xx_ep0_internal_request(udc, IUDMA_EP0_TXCHAN, 0); in bcm63xx_ep0_one_round()
1656 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_RXCHAN]); in bcm63xx_ep0_one_round()
1657 bcm63xx_ep0_nuke_reply(udc, 0); in bcm63xx_ep0_one_round()
1671 if (udc->ep0_req_completed) { in bcm63xx_ep0_one_round()
1672 bcm63xx_ep0_read_complete(udc); in bcm63xx_ep0_one_round()
1675 iudma_reset_channel(udc, &udc->iudma[IUDMA_EP0_TXCHAN]); in bcm63xx_ep0_one_round()
1676 udc->ep0_request = NULL; in bcm63xx_ep0_one_round()
1695 struct usb_request *r = udc->ep0_reply; in bcm63xx_ep0_one_round()
1703 bcm63xx_ep0_complete(udc, r, 0); in bcm63xx_ep0_one_round()
1704 udc->ep0_reply = NULL; in bcm63xx_ep0_one_round()
1712 if (udc->ep0state == ep0state) in bcm63xx_ep0_one_round()
1715 udc->ep0state = ep0state; in bcm63xx_ep0_one_round()
1735 struct bcm63xx_udc *udc = container_of(w, struct bcm63xx_udc, ep0_wq); in bcm63xx_ep0_process() local
1736 spin_lock_irq(&udc->lock); in bcm63xx_ep0_process()
1737 while (bcm63xx_ep0_one_round(udc) == 0) in bcm63xx_ep0_process()
1739 spin_unlock_irq(&udc->lock); in bcm63xx_ep0_process()
1743 * Standard UDC gadget operations
1752 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_get_frame() local
1754 return (usbd_readl(udc, USBD_STATUS_REG) & in bcm63xx_udc_get_frame()
1767 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_pullup() local
1771 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_pullup()
1772 if (is_on && udc->ep0state == EP0_SHUTDOWN) { in bcm63xx_udc_pullup()
1773 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_udc_pullup()
1774 udc->ep0state = EP0_REQUEUE; in bcm63xx_udc_pullup()
1775 bcm63xx_fifo_setup(udc); in bcm63xx_udc_pullup()
1776 bcm63xx_fifo_reset(udc); in bcm63xx_udc_pullup()
1777 bcm63xx_ep_setup(udc); in bcm63xx_udc_pullup()
1779 bitmap_zero(&udc->wedgemap, BCM63XX_NUM_EP); in bcm63xx_udc_pullup()
1781 bcm63xx_set_stall(udc, &udc->bep[i], false); in bcm63xx_udc_pullup()
1783 bcm63xx_set_ctrl_irqs(udc, true); in bcm63xx_udc_pullup()
1786 } else if (!is_on && udc->ep0state != EP0_SHUTDOWN) { in bcm63xx_udc_pullup()
1789 udc->ep0_req_shutdown = 1; in bcm63xx_udc_pullup()
1790 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_pullup()
1793 schedule_work(&udc->ep0_wq); in bcm63xx_udc_pullup()
1794 if (udc->ep0state == EP0_SHUTDOWN) in bcm63xx_udc_pullup()
1798 bcm63xx_set_ctrl_irqs(udc, false); in bcm63xx_udc_pullup()
1799 cancel_work_sync(&udc->ep0_wq); in bcm63xx_udc_pullup()
1803 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_pullup()
1815 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_start() local
1821 if (!udc) in bcm63xx_udc_start()
1823 if (udc->driver) in bcm63xx_udc_start()
1826 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_start()
1828 set_clocks(udc, true); in bcm63xx_udc_start()
1829 bcm63xx_fifo_setup(udc); in bcm63xx_udc_start()
1830 bcm63xx_ep_init(udc); in bcm63xx_udc_start()
1831 bcm63xx_ep_setup(udc); in bcm63xx_udc_start()
1832 bcm63xx_fifo_reset(udc); in bcm63xx_udc_start()
1833 bcm63xx_select_phy_mode(udc, true); in bcm63xx_udc_start()
1835 udc->driver = driver; in bcm63xx_udc_start()
1837 udc->gadget.dev.of_node = udc->dev->of_node; in bcm63xx_udc_start()
1839 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_start()
1851 struct bcm63xx_udc *udc = gadget_to_udc(gadget); in bcm63xx_udc_stop() local
1854 spin_lock_irqsave(&udc->lock, flags); in bcm63xx_udc_stop()
1856 udc->driver = NULL; in bcm63xx_udc_stop()
1866 bcm63xx_select_phy_mode(udc, false); in bcm63xx_udc_stop()
1867 set_clocks(udc, false); in bcm63xx_udc_stop()
1869 spin_unlock_irqrestore(&udc->lock, flags); in bcm63xx_udc_stop()
1887 * @udc: Reference to the device controller.
1894 static void bcm63xx_update_cfg_iface(struct bcm63xx_udc *udc) in bcm63xx_update_cfg_iface() argument
1896 u32 reg = usbd_readl(udc, USBD_STATUS_REG); in bcm63xx_update_cfg_iface()
1898 udc->cfg = (reg & USBD_STATUS_CFG_MASK) >> USBD_STATUS_CFG_SHIFT; in bcm63xx_update_cfg_iface()
1899 udc->iface = (reg & USBD_STATUS_INTF_MASK) >> USBD_STATUS_INTF_SHIFT; in bcm63xx_update_cfg_iface()
1900 udc->alt_iface = (reg & USBD_STATUS_ALTINTF_MASK) >> in bcm63xx_update_cfg_iface()
1902 bcm63xx_ep_setup(udc); in bcm63xx_update_cfg_iface()
1907 * @udc: Reference to the device controller.
1912 static int bcm63xx_update_link_speed(struct bcm63xx_udc *udc) in bcm63xx_update_link_speed() argument
1914 u32 reg = usbd_readl(udc, USBD_STATUS_REG); in bcm63xx_update_link_speed()
1915 enum usb_device_speed oldspeed = udc->gadget.speed; in bcm63xx_update_link_speed()
1919 udc->gadget.speed = USB_SPEED_HIGH; in bcm63xx_update_link_speed()
1922 udc->gadget.speed = USB_SPEED_FULL; in bcm63xx_update_link_speed()
1926 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_update_link_speed()
1927 dev_err(udc->dev, in bcm63xx_update_link_speed()
1932 if (udc->gadget.speed != oldspeed) { in bcm63xx_update_link_speed()
1933 dev_info(udc->dev, "link up, %s-speed mode\n", in bcm63xx_update_link_speed()
1934 udc->gadget.speed == USB_SPEED_HIGH ? "high" : "full"); in bcm63xx_update_link_speed()
1943 * @udc: Reference to the device controller.
1952 static void bcm63xx_update_wedge(struct bcm63xx_udc *udc, bool new_status) in bcm63xx_update_wedge() argument
1956 for_each_set_bit(i, &udc->wedgemap, BCM63XX_NUM_EP) { in bcm63xx_update_wedge()
1957 bcm63xx_set_stall(udc, &udc->bep[i], new_status); in bcm63xx_update_wedge()
1959 clear_bit(i, &udc->wedgemap); in bcm63xx_update_wedge()
1973 struct bcm63xx_udc *udc = dev_id; in bcm63xx_udc_ctrl_isr() local
1977 stat = usbd_readl(udc, USBD_EVENT_IRQ_STATUS_REG) & in bcm63xx_udc_ctrl_isr()
1978 usbd_readl(udc, USBD_EVENT_IRQ_MASK_REG); in bcm63xx_udc_ctrl_isr()
1980 usbd_writel(udc, stat, USBD_EVENT_IRQ_STATUS_REG); in bcm63xx_udc_ctrl_isr()
1982 spin_lock(&udc->lock); in bcm63xx_udc_ctrl_isr()
1986 if (!(usbd_readl(udc, USBD_EVENTS_REG) & in bcm63xx_udc_ctrl_isr()
1988 udc->gadget.speed != USB_SPEED_UNKNOWN) in bcm63xx_udc_ctrl_isr()
1989 dev_info(udc->dev, "link down\n"); in bcm63xx_udc_ctrl_isr()
1991 udc->gadget.speed = USB_SPEED_UNKNOWN; in bcm63xx_udc_ctrl_isr()
1995 bcm63xx_fifo_setup(udc); in bcm63xx_udc_ctrl_isr()
1996 bcm63xx_fifo_reset(udc); in bcm63xx_udc_ctrl_isr()
1997 bcm63xx_ep_setup(udc); in bcm63xx_udc_ctrl_isr()
1999 bcm63xx_update_wedge(udc, false); in bcm63xx_udc_ctrl_isr()
2001 udc->ep0_req_reset = 1; in bcm63xx_udc_ctrl_isr()
2002 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2006 if (bcm63xx_update_link_speed(udc)) { in bcm63xx_udc_ctrl_isr()
2007 bcm63xx_fifo_setup(udc); in bcm63xx_udc_ctrl_isr()
2008 bcm63xx_ep_setup(udc); in bcm63xx_udc_ctrl_isr()
2010 bcm63xx_update_wedge(udc, true); in bcm63xx_udc_ctrl_isr()
2013 bcm63xx_update_cfg_iface(udc); in bcm63xx_udc_ctrl_isr()
2014 udc->ep0_req_set_cfg = 1; in bcm63xx_udc_ctrl_isr()
2015 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2018 bcm63xx_update_cfg_iface(udc); in bcm63xx_udc_ctrl_isr()
2019 udc->ep0_req_set_iface = 1; in bcm63xx_udc_ctrl_isr()
2020 schedule_work(&udc->ep0_wq); in bcm63xx_udc_ctrl_isr()
2022 spin_unlock(&udc->lock); in bcm63xx_udc_ctrl_isr()
2024 if (disconnected && udc->driver) in bcm63xx_udc_ctrl_isr()
2025 udc->driver->disconnect(&udc->gadget); in bcm63xx_udc_ctrl_isr()
2026 else if (bus_reset && udc->driver) in bcm63xx_udc_ctrl_isr()
2027 usb_gadget_udc_reset(&udc->gadget, udc->driver); in bcm63xx_udc_ctrl_isr()
2045 struct bcm63xx_udc *udc = iudma->udc; in bcm63xx_udc_data_isr() local
2052 spin_lock(&udc->lock); in bcm63xx_udc_data_isr()
2054 usb_dmac_writel(udc, ENETDMAC_IR_BUFDONE_MASK, in bcm63xx_udc_data_isr()
2057 rc = iudma_read(udc, iudma); in bcm63xx_udc_data_isr()
2062 req = udc->ep0_request; in bcm63xx_udc_data_isr()
2070 udc->ep0_req_completed = 1; in bcm63xx_udc_data_isr()
2072 schedule_work(&udc->ep0_wq); in bcm63xx_udc_data_isr()
2078 iudma_write(udc, iudma, breq); in bcm63xx_udc_data_isr()
2099 iudma_write(udc, iudma, next); in bcm63xx_udc_data_isr()
2102 iudma_write(udc, iudma, breq); in bcm63xx_udc_data_isr()
2106 spin_unlock(&udc->lock); in bcm63xx_udc_data_isr()
2109 usb_gadget_unmap_request(&udc->gadget, req, iudma->is_tx); in bcm63xx_udc_data_isr()
2130 struct bcm63xx_udc *udc = s->private; in bcm63xx_usbd_dbg_show() local
2132 if (!udc->driver) in bcm63xx_usbd_dbg_show()
2136 bcm63xx_ep0_state_names[udc->ep0state]); in bcm63xx_usbd_dbg_show()
2138 udc->ep0_req_reset ? "reset " : "", in bcm63xx_usbd_dbg_show()
2139 udc->ep0_req_set_cfg ? "set_cfg " : "", in bcm63xx_usbd_dbg_show()
2140 udc->ep0_req_set_iface ? "set_iface " : "", in bcm63xx_usbd_dbg_show()
2141 udc->ep0_req_shutdown ? "shutdown " : "", in bcm63xx_usbd_dbg_show()
2142 udc->ep0_request ? "pending " : "", in bcm63xx_usbd_dbg_show()
2143 udc->ep0_req_completed ? "completed " : "", in bcm63xx_usbd_dbg_show()
2144 udc->ep0_reply ? "reply " : ""); in bcm63xx_usbd_dbg_show()
2146 udc->cfg, udc->iface, udc->alt_iface); in bcm63xx_usbd_dbg_show()
2149 usbd_readl(udc, USBD_CONTROL_REG), in bcm63xx_usbd_dbg_show()
2150 usbd_readl(udc, USBD_STRAPS_REG), in bcm63xx_usbd_dbg_show()
2151 usbd_readl(udc, USBD_STATUS_REG)); in bcm63xx_usbd_dbg_show()
2153 usbd_readl(udc, USBD_EVENTS_REG), in bcm63xx_usbd_dbg_show()
2154 usbd_readl(udc, USBD_STALL_REG)); in bcm63xx_usbd_dbg_show()
2169 struct bcm63xx_udc *udc = s->private; in bcm63xx_iudma_dbg_show() local
2173 if (!udc->driver) in bcm63xx_iudma_dbg_show()
2177 struct iudma_ch *iudma = &udc->iudma[ch_idx]; in bcm63xx_iudma_dbg_show()
2196 usb_dmac_readl(udc, ENETDMAC_CHANCFG_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2197 usb_dmac_readl(udc, ENETDMAC_IR_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2198 usb_dmac_readl(udc, ENETDMAC_IRMASK_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2199 usb_dmac_readl(udc, ENETDMAC_MAXBURST_REG, ch_idx)); in bcm63xx_iudma_dbg_show()
2201 sram2 = usb_dmas_readl(udc, ENETDMAS_SRAM2_REG, ch_idx); in bcm63xx_iudma_dbg_show()
2202 sram3 = usb_dmas_readl(udc, ENETDMAS_SRAM3_REG, ch_idx); in bcm63xx_iudma_dbg_show()
2204 usb_dmas_readl(udc, ENETDMAS_RSTART_REG, ch_idx), in bcm63xx_iudma_dbg_show()
2207 usb_dmas_readl(udc, ENETDMAS_SRAM4_REG, ch_idx)); in bcm63xx_iudma_dbg_show()
2243 * @udc: Reference to the device controller.
2245 static void bcm63xx_udc_init_debugfs(struct bcm63xx_udc *udc) in bcm63xx_udc_init_debugfs() argument
2252 root = debugfs_create_dir(udc->gadget.name, usb_debug_root); in bcm63xx_udc_init_debugfs()
2253 udc->debugfs_root = root; in bcm63xx_udc_init_debugfs()
2255 debugfs_create_file("usbd", 0400, root, udc, &bcm63xx_usbd_dbg_fops); in bcm63xx_udc_init_debugfs()
2256 debugfs_create_file("iudma", 0400, root, udc, &bcm63xx_iudma_dbg_fops); in bcm63xx_udc_init_debugfs()
2261 * @udc: Reference to the device controller.
2265 static void bcm63xx_udc_cleanup_debugfs(struct bcm63xx_udc *udc) in bcm63xx_udc_cleanup_debugfs() argument
2267 debugfs_remove_recursive(udc->debugfs_root); in bcm63xx_udc_cleanup_debugfs()
2275 * bcm63xx_udc_probe - Initialize a new instance of the UDC.
2285 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()
2301 udc->usbd_regs = devm_platform_ioremap_resource(pdev, 0); in bcm63xx_udc_probe()
2302 if (IS_ERR(udc->usbd_regs)) in bcm63xx_udc_probe()
2303 return PTR_ERR(udc->usbd_regs); in bcm63xx_udc_probe()
2305 udc->iudma_regs = devm_platform_ioremap_resource(pdev, 1); in bcm63xx_udc_probe()
2306 if (IS_ERR(udc->iudma_regs)) in bcm63xx_udc_probe()
2307 return PTR_ERR(udc->iudma_regs); in bcm63xx_udc_probe()
2309 spin_lock_init(&udc->lock); in bcm63xx_udc_probe()
2310 INIT_WORK(&udc->ep0_wq, bcm63xx_ep0_process); in bcm63xx_udc_probe()
2312 udc->gadget.ops = &bcm63xx_udc_ops; in bcm63xx_udc_probe()
2313 udc->gadget.name = dev_name(dev); in bcm63xx_udc_probe()
2316 udc->gadget.max_speed = USB_SPEED_HIGH; in bcm63xx_udc_probe()
2318 udc->gadget.max_speed = USB_SPEED_FULL; in bcm63xx_udc_probe()
2321 rc = bcm63xx_init_udc_hw(udc); in bcm63xx_udc_probe()
2332 dev_name(dev), udc) < 0) in bcm63xx_udc_probe()
2341 dev_name(dev), &udc->iudma[i]) < 0) in bcm63xx_udc_probe()
2345 bcm63xx_udc_init_debugfs(udc); in bcm63xx_udc_probe()
2346 rc = usb_add_gadget_udc(dev, &udc->gadget); in bcm63xx_udc_probe()
2350 bcm63xx_udc_cleanup_debugfs(udc); in bcm63xx_udc_probe()
2352 bcm63xx_uninit_udc_hw(udc); in bcm63xx_udc_probe()
2366 struct bcm63xx_udc *udc = platform_get_drvdata(pdev); in bcm63xx_udc_remove() local
2368 bcm63xx_udc_cleanup_debugfs(udc); in bcm63xx_udc_remove()
2369 usb_del_gadget_udc(&udc->gadget); in bcm63xx_udc_remove()
2370 BUG_ON(udc->driver); in bcm63xx_udc_remove()
2372 bcm63xx_uninit_udc_hw(udc); in bcm63xx_udc_remove()