Lines Matching full:vhub

3  * aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
27 #include "vhub.h"
33 struct ast_vhub *vhub = ep->vhub; in ast_vhub_done() local
44 usb_gadget_unmap_request_by_dev(&vhub->pdev->dev, in ast_vhub_done()
54 spin_unlock(&ep->vhub->lock); in ast_vhub_done()
56 spin_lock(&ep->vhub->lock); in ast_vhub_done()
95 struct ast_vhub *vhub = data; in ast_vhub_irq() local
100 if (!vhub->ep0_bufs) in ast_vhub_irq()
103 spin_lock(&vhub->lock); in ast_vhub_irq()
106 istat = readl(vhub->regs + AST_VHUB_ISR); in ast_vhub_irq()
109 writel(istat, vhub->regs + AST_VHUB_ISR); in ast_vhub_irq()
112 UDCVDBG(vhub, "irq status=%08x, ep_acks=%08x ep_nacks=%08x\n", in ast_vhub_irq()
114 readl(vhub->regs + AST_VHUB_EP_ACK_ISR), in ast_vhub_irq()
115 readl(vhub->regs + AST_VHUB_EP_NACK_ISR)); in ast_vhub_irq()
119 u32 ep_acks = readl(vhub->regs + AST_VHUB_EP_ACK_ISR); in ast_vhub_irq()
120 writel(ep_acks, vhub->regs + AST_VHUB_EP_ACK_ISR); in ast_vhub_irq()
122 for (i = 0; ep_acks && i < vhub->max_epns; i++) { in ast_vhub_irq()
125 ast_vhub_epn_ack_irq(&vhub->epns[i]); in ast_vhub_irq()
132 if (istat & vhub->port_irq_mask) { in ast_vhub_irq()
133 for (i = 0; i < vhub->max_ports; i++) { in ast_vhub_irq()
135 ast_vhub_dev_irq(&vhub->ports[i].dev); in ast_vhub_irq()
139 /* Handle top-level vHub EP0 interrupts */ in ast_vhub_irq()
144 ast_vhub_ep0_handle_ack(&vhub->ep0, true); in ast_vhub_irq()
146 ast_vhub_ep0_handle_ack(&vhub->ep0, false); in ast_vhub_irq()
148 ast_vhub_ep0_handle_setup(&vhub->ep0); in ast_vhub_irq()
156 ast_vhub_hub_resume(vhub); in ast_vhub_irq()
158 ast_vhub_hub_suspend(vhub); in ast_vhub_irq()
160 ast_vhub_hub_reset(vhub); in ast_vhub_irq()
164 spin_unlock(&vhub->lock); in ast_vhub_irq()
168 void ast_vhub_init_hw(struct ast_vhub *vhub) in ast_vhub_init_hw() argument
172 UDCDBG(vhub,"(Re)Starting HW ...\n"); in ast_vhub_init_hw()
198 writel(ctrl, vhub->regs + AST_VHUB_CTRL); in ast_vhub_init_hw()
204 writel(ctrl, vhub->regs + AST_VHUB_CTRL); in ast_vhub_init_hw()
210 port_mask = GENMASK(vhub->max_ports, 1); in ast_vhub_init_hw()
214 port_mask, vhub->regs + AST_VHUB_SW_RESET); in ast_vhub_init_hw()
216 writel(0, vhub->regs + AST_VHUB_SW_RESET); in ast_vhub_init_hw()
219 epn_mask = GENMASK(vhub->max_epns - 1, 0); in ast_vhub_init_hw()
220 writel(0, vhub->regs + AST_VHUB_EP_ACK_IER); in ast_vhub_init_hw()
221 writel(0, vhub->regs + AST_VHUB_EP_NACK_IER); in ast_vhub_init_hw()
222 writel(epn_mask, vhub->regs + AST_VHUB_EP_ACK_ISR); in ast_vhub_init_hw()
223 writel(epn_mask, vhub->regs + AST_VHUB_EP_NACK_ISR); in ast_vhub_init_hw()
226 writel(0, vhub->regs + AST_VHUB_EP0_CTRL); in ast_vhub_init_hw()
229 vhub->regs + AST_VHUB_EP1_CTRL); in ast_vhub_init_hw()
230 writel(0, vhub->regs + AST_VHUB_EP1_STS_CHG); in ast_vhub_init_hw()
233 writel(vhub->ep0.buf_dma, vhub->regs + AST_VHUB_EP0_DATA); in ast_vhub_init_hw()
236 writel(0, vhub->regs + AST_VHUB_CONF); in ast_vhub_init_hw()
239 if (vhub->force_usb1) in ast_vhub_init_hw()
243 writel(ctrl, vhub->regs + AST_VHUB_CTRL); in ast_vhub_init_hw()
253 vhub->regs + AST_VHUB_IER); in ast_vhub_init_hw()
258 struct ast_vhub *vhub = platform_get_drvdata(pdev); in ast_vhub_remove() local
262 if (!vhub || !vhub->regs) in ast_vhub_remove()
266 for (i = 0; i < vhub->max_ports; i++) in ast_vhub_remove()
267 ast_vhub_del_dev(&vhub->ports[i].dev); in ast_vhub_remove()
269 spin_lock_irqsave(&vhub->lock, flags); in ast_vhub_remove()
272 writel(0, vhub->regs + AST_VHUB_IER); in ast_vhub_remove()
273 writel(VHUB_IRQ_ACK_ALL, vhub->regs + AST_VHUB_ISR); in ast_vhub_remove()
278 vhub->regs + AST_VHUB_CTRL); in ast_vhub_remove()
280 if (vhub->clk) in ast_vhub_remove()
281 clk_disable_unprepare(vhub->clk); in ast_vhub_remove()
283 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_remove()
285 if (vhub->ep0_bufs) in ast_vhub_remove()
288 (vhub->max_ports + 1), in ast_vhub_remove()
289 vhub->ep0_bufs, in ast_vhub_remove()
290 vhub->ep0_bufs_dma); in ast_vhub_remove()
291 vhub->ep0_bufs = NULL; in ast_vhub_remove()
297 struct ast_vhub *vhub; in ast_vhub_probe() local
302 vhub = devm_kzalloc(&pdev->dev, sizeof(*vhub), GFP_KERNEL); in ast_vhub_probe()
303 if (!vhub) in ast_vhub_probe()
306 rc = of_property_read_u32(np, "aspeed,vhub-downstream-ports", in ast_vhub_probe()
307 &vhub->max_ports); in ast_vhub_probe()
309 vhub->max_ports = AST_VHUB_NUM_PORTS; in ast_vhub_probe()
311 vhub->ports = devm_kcalloc(&pdev->dev, vhub->max_ports, in ast_vhub_probe()
312 sizeof(*vhub->ports), GFP_KERNEL); in ast_vhub_probe()
313 if (!vhub->ports) in ast_vhub_probe()
316 rc = of_property_read_u32(np, "aspeed,vhub-generic-endpoints", in ast_vhub_probe()
317 &vhub->max_epns); in ast_vhub_probe()
319 vhub->max_epns = AST_VHUB_NUM_GEN_EPs; in ast_vhub_probe()
321 vhub->epns = devm_kcalloc(&pdev->dev, vhub->max_epns, in ast_vhub_probe()
322 sizeof(*vhub->epns), GFP_KERNEL); in ast_vhub_probe()
323 if (!vhub->epns) in ast_vhub_probe()
326 spin_lock_init(&vhub->lock); in ast_vhub_probe()
327 vhub->pdev = pdev; in ast_vhub_probe()
328 vhub->port_irq_mask = GENMASK(VHUB_IRQ_DEV1_BIT + vhub->max_ports - 1, in ast_vhub_probe()
331 vhub->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in ast_vhub_probe()
332 if (IS_ERR(vhub->regs)) { in ast_vhub_probe()
334 return PTR_ERR(vhub->regs); in ast_vhub_probe()
336 UDCDBG(vhub, "vHub@%pR mapped @%p\n", res, vhub->regs); in ast_vhub_probe()
338 platform_set_drvdata(pdev, vhub); in ast_vhub_probe()
340 vhub->clk = devm_clk_get(&pdev->dev, NULL); in ast_vhub_probe()
341 if (IS_ERR(vhub->clk)) { in ast_vhub_probe()
342 rc = PTR_ERR(vhub->clk); in ast_vhub_probe()
345 rc = clk_prepare_enable(vhub->clk); in ast_vhub_probe()
354 vhub->force_usb1 = true; in ast_vhub_probe()
357 writel(0, vhub->regs + AST_VHUB_IER); in ast_vhub_probe()
358 writel(VHUB_IRQ_ACK_ALL, vhub->regs + AST_VHUB_ISR); in ast_vhub_probe()
361 vhub->irq = platform_get_irq(pdev, 0); in ast_vhub_probe()
362 if (vhub->irq < 0) { in ast_vhub_probe()
363 rc = vhub->irq; in ast_vhub_probe()
366 rc = devm_request_irq(&pdev->dev, vhub->irq, ast_vhub_irq, 0, in ast_vhub_probe()
367 KBUILD_MODNAME, vhub); in ast_vhub_probe()
375 * one per port and one for the vHub itself in ast_vhub_probe()
377 vhub->ep0_bufs = dma_alloc_coherent(&pdev->dev, in ast_vhub_probe()
379 (vhub->max_ports + 1), in ast_vhub_probe()
380 &vhub->ep0_bufs_dma, GFP_KERNEL); in ast_vhub_probe()
381 if (!vhub->ep0_bufs) { in ast_vhub_probe()
386 UDCVDBG(vhub, "EP0 DMA buffers @%p (DMA 0x%08x)\n", in ast_vhub_probe()
387 vhub->ep0_bufs, (u32)vhub->ep0_bufs_dma); in ast_vhub_probe()
389 /* Init vHub EP0 */ in ast_vhub_probe()
390 ast_vhub_init_ep0(vhub, &vhub->ep0, NULL); in ast_vhub_probe()
393 for (i = 0; i < vhub->max_ports && rc == 0; i++) in ast_vhub_probe()
394 rc = ast_vhub_init_dev(vhub, i); in ast_vhub_probe()
399 rc = ast_vhub_init_hub(vhub); in ast_vhub_probe()
404 ast_vhub_init_hw(vhub); in ast_vhub_probe()
407 vhub->force_usb1 ? 1 : 2); in ast_vhub_probe()
417 .compatible = "aspeed,ast2400-usb-vhub",
420 .compatible = "aspeed,ast2500-usb-vhub",
423 .compatible = "aspeed,ast2600-usb-vhub",
439 MODULE_DESCRIPTION("Aspeed vHub udc driver");