Lines Matching +full:usb +full:- +full:glue

1 // SPDX-License-Identifier: GPL-2.0
3 * Texas Instruments DA8xx/OMAP-L1x "glue layer"
5 * Copyright (c) 2008-2009 MontaVista Software, Inc. <source@mvista.com>
7 * Based on the DaVinci "glue layer" code.
8 * Copyright (C) 2005-2006 by Texas Instruments
23 #include <linux/dma-mapping.h>
24 #include <linux/usb/usb_phy_generic.h>
32 /* USB 2.0 OTG module registers */
46 #define DA8XX_USB_GENERIC_RNDIS_EP_SIZE_REG(n) (0x50 + (((n) - 1) << 2))
54 /* USB interrupt register bits */
76 * - not read/write INTRUSB/INTRUSBE (except during
78 * - use INTSET/INTCLR instead.
82 * da8xx_musb_enable - enable interrupts
86 void __iomem *reg_base = musb->ctrl_base; in da8xx_musb_enable()
90 mask = ((musb->epmask & DA8XX_USB_TX_EP_MASK) << DA8XX_INTR_TX_SHIFT) | in da8xx_musb_enable()
91 ((musb->epmask & DA8XX_USB_RX_EP_MASK) << DA8XX_INTR_RX_SHIFT) | in da8xx_musb_enable()
101 * da8xx_musb_disable - disable HDRC and flush interrupts
105 void __iomem *reg_base = musb->ctrl_base; in da8xx_musb_disable()
125 void __iomem *mregs = musb->mregs; in otg_timer()
130 * We poll because DaVinci's won't expose several OTG-critical in otg_timer()
134 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, in otg_timer()
135 usb_otg_state_string(musb->xceiv->otg->state)); in otg_timer()
137 spin_lock_irqsave(&musb->lock, flags); in otg_timer()
138 switch (musb->xceiv->otg->state) { in otg_timer()
141 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in otg_timer()
143 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in otg_timer()
145 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in otg_timer()
148 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in otg_timer()
155 * RTL seems to mis-handle session "start" otherwise (or in in otg_timer()
160 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in otg_timer()
163 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in otg_timer()
164 musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG, in otg_timer()
169 * There's no ID-changed IRQ, so we have no good way to tell in otg_timer()
170 * when to switch to the A-Default state machine (by setting in otg_timer()
175 * grounded and we're now in the A-Default state machine. in otg_timer()
183 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in otg_timer()
185 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in otg_timer()
190 spin_unlock_irqrestore(&musb->lock, flags); in otg_timer()
201 if (musb->is_active || (musb->a_wait_bcon == 0 && in da8xx_musb_try_idle()
202 musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { in da8xx_musb_try_idle()
203 dev_dbg(musb->controller, "%s active, deleting timer\n", in da8xx_musb_try_idle()
204 usb_otg_state_string(musb->xceiv->otg->state)); in da8xx_musb_try_idle()
205 del_timer(&musb->dev_timer); in da8xx_musb_try_idle()
210 if (time_after(last_timer, timeout) && timer_pending(&musb->dev_timer)) { in da8xx_musb_try_idle()
211 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n"); in da8xx_musb_try_idle()
216 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", in da8xx_musb_try_idle()
217 usb_otg_state_string(musb->xceiv->otg->state), in da8xx_musb_try_idle()
218 jiffies_to_msecs(timeout - jiffies)); in da8xx_musb_try_idle()
219 mod_timer(&musb->dev_timer, timeout); in da8xx_musb_try_idle()
225 void __iomem *reg_base = musb->ctrl_base; in da8xx_musb_interrupt()
230 spin_lock_irqsave(&musb->lock, flags); in da8xx_musb_interrupt()
237 /* Acknowledge and handle non-CPPI interrupts */ in da8xx_musb_interrupt()
243 dev_dbg(musb->controller, "USB IRQ %08x\n", status); in da8xx_musb_interrupt()
245 musb->int_rx = (status & DA8XX_INTR_RX_MASK) >> DA8XX_INTR_RX_SHIFT; in da8xx_musb_interrupt()
246 musb->int_tx = (status & DA8XX_INTR_TX_MASK) >> DA8XX_INTR_TX_SHIFT; in da8xx_musb_interrupt()
247 musb->int_usb = (status & DA8XX_INTR_USB_MASK) >> DA8XX_INTR_USB_SHIFT; in da8xx_musb_interrupt()
259 void __iomem *mregs = musb->mregs; in da8xx_musb_interrupt()
263 err = musb->int_usb & MUSB_INTR_VBUSERROR; in da8xx_musb_interrupt()
268 * means it's not uncommon for bus-powered devices in da8xx_musb_interrupt()
272 * seems to allow a better one: "re"-starting sessions in da8xx_musb_interrupt()
276 musb->int_usb &= ~MUSB_INTR_VBUSERROR; in da8xx_musb_interrupt()
277 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; in da8xx_musb_interrupt()
278 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in da8xx_musb_interrupt()
282 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in da8xx_musb_interrupt()
283 portstate(musb->port1_status |= USB_PORT_STAT_POWER); in da8xx_musb_interrupt()
284 del_timer(&musb->dev_timer); in da8xx_musb_interrupt()
285 } else if (!(musb->int_usb & MUSB_INTR_BABBLE)) { in da8xx_musb_interrupt()
290 * controller; otherwise, the host-mode flag is lost in da8xx_musb_interrupt()
294 musb->is_active = 0; in da8xx_musb_interrupt()
296 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in da8xx_musb_interrupt()
297 portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); in da8xx_musb_interrupt()
300 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", in da8xx_musb_interrupt()
302 usb_otg_state_string(musb->xceiv->otg->state), in da8xx_musb_interrupt()
308 if (musb->int_tx || musb->int_rx || musb->int_usb) in da8xx_musb_interrupt()
312 /* EOI needs to be written for the IRQ to be re-asserted. */ in da8xx_musb_interrupt()
317 if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) in da8xx_musb_interrupt()
318 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in da8xx_musb_interrupt()
320 spin_unlock_irqrestore(&musb->lock, flags); in da8xx_musb_interrupt()
327 struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); in da8xx_musb_set_mode() local
334 if (!musb->is_initialized) in da8xx_musb_set_mode()
335 return phy_set_mode(glue->phy, PHY_MODE_USB_OTG); in da8xx_musb_set_mode()
348 return -EINVAL; in da8xx_musb_set_mode()
351 return phy_set_mode(glue->phy, phy_mode); in da8xx_musb_set_mode()
356 struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); in da8xx_musb_init() local
357 void __iomem *reg_base = musb->ctrl_base; in da8xx_musb_init()
359 int ret = -ENODEV; in da8xx_musb_init()
361 musb->mregs += DA8XX_MENTOR_CORE_OFFSET; in da8xx_musb_init()
363 ret = clk_prepare_enable(glue->clk); in da8xx_musb_init()
365 dev_err(glue->dev, "failed to enable clock\n"); in da8xx_musb_init()
374 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); in da8xx_musb_init()
375 if (IS_ERR_OR_NULL(musb->xceiv)) { in da8xx_musb_init()
376 ret = -EPROBE_DEFER; in da8xx_musb_init()
380 timer_setup(&musb->dev_timer, otg_timer, 0); in da8xx_musb_init()
385 /* Start the on-chip PHY and its PLL. */ in da8xx_musb_init()
386 ret = phy_init(glue->phy); in da8xx_musb_init()
388 dev_err(glue->dev, "Failed to init phy.\n"); in da8xx_musb_init()
392 ret = phy_power_on(glue->phy); in da8xx_musb_init()
394 dev_err(glue->dev, "Failed to power on phy.\n"); in da8xx_musb_init()
404 musb->isr = da8xx_musb_interrupt; in da8xx_musb_init()
408 phy_exit(glue->phy); in da8xx_musb_init()
410 clk_disable_unprepare(glue->clk); in da8xx_musb_init()
416 struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); in da8xx_musb_exit() local
418 del_timer_sync(&musb->dev_timer); in da8xx_musb_exit()
420 phy_power_off(glue->phy); in da8xx_musb_exit()
421 phy_exit(glue->phy); in da8xx_musb_exit()
422 clk_disable_unprepare(glue->clk); in da8xx_musb_exit()
424 usb_put_phy(musb->xceiv); in da8xx_musb_exit()
447 struct musb *musb = c->musb; in da8xx_dma_controller_callback()
448 void __iomem *reg_base = musb->ctrl_base; in da8xx_dma_controller_callback()
462 controller->dma_callback = da8xx_dma_controller_callback; in da8xx_dma_controller_create()
489 .name = "musb-hdrc",
501 OF_DEV_AUXDATA("ti,da830-cppi41", 0x01e01000, "cppi41-dmaengine",
508 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); in da8xx_probe()
509 struct da8xx_glue *glue; in da8xx_probe() local
512 struct device_node *np = pdev->dev.of_node; in da8xx_probe()
515 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); in da8xx_probe()
516 if (!glue) in da8xx_probe()
517 return -ENOMEM; in da8xx_probe()
519 clk = devm_clk_get(&pdev->dev, NULL); in da8xx_probe()
521 dev_err(&pdev->dev, "failed to get clock\n"); in da8xx_probe()
525 glue->phy = devm_phy_get(&pdev->dev, "usb-phy"); in da8xx_probe()
526 if (IS_ERR(glue->phy)) in da8xx_probe()
527 return dev_err_probe(&pdev->dev, PTR_ERR(glue->phy), in da8xx_probe()
530 glue->dev = &pdev->dev; in da8xx_probe()
531 glue->clk = clk; in da8xx_probe()
534 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in da8xx_probe()
536 return -ENOMEM; in da8xx_probe()
538 pdata->config = &da8xx_config; in da8xx_probe()
539 pdata->mode = musb_get_mode(&pdev->dev); in da8xx_probe()
540 pdata->power = get_vbus_power(&pdev->dev); in da8xx_probe()
543 pdata->platform_ops = &da8xx_ops; in da8xx_probe()
545 glue->usb_phy = usb_phy_generic_register(); in da8xx_probe()
546 ret = PTR_ERR_OR_ZERO(glue->usb_phy); in da8xx_probe()
548 dev_err(&pdev->dev, "failed to register usb_phy\n"); in da8xx_probe()
551 platform_set_drvdata(pdev, glue); in da8xx_probe()
553 ret = of_platform_populate(pdev->dev.of_node, NULL, in da8xx_probe()
554 da8xx_auxdata_lookup, &pdev->dev); in da8xx_probe()
559 pinfo.parent = &pdev->dev; in da8xx_probe()
560 pinfo.res = pdev->resource; in da8xx_probe()
561 pinfo.num_res = pdev->num_resources; in da8xx_probe()
567 glue->musb = platform_device_register_full(&pinfo); in da8xx_probe()
568 ret = PTR_ERR_OR_ZERO(glue->musb); in da8xx_probe()
570 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); in da8xx_probe()
571 usb_phy_generic_unregister(glue->usb_phy); in da8xx_probe()
579 struct da8xx_glue *glue = platform_get_drvdata(pdev); in da8xx_remove() local
581 platform_device_unregister(glue->musb); in da8xx_remove()
582 usb_phy_generic_unregister(glue->usb_phy); in da8xx_remove()
591 struct da8xx_glue *glue = dev_get_drvdata(dev); in da8xx_suspend() local
593 ret = phy_power_off(glue->phy); in da8xx_suspend()
596 clk_disable_unprepare(glue->clk); in da8xx_suspend()
604 struct da8xx_glue *glue = dev_get_drvdata(dev); in da8xx_resume() local
606 ret = clk_prepare_enable(glue->clk); in da8xx_resume()
609 return phy_power_on(glue->phy); in da8xx_resume()
618 .compatible = "ti,da830-musb",
629 .name = "musb-da8xx",
635 MODULE_DESCRIPTION("DA8xx/OMAP-L1x MUSB Glue Layer");