Lines Matching +full:otg +full:- +full:rev

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>
8 * Copyright (C) 2005-2006 by Texas Instruments
24 #include <linux/dma-mapping.h>
33 /* USB 2.0 OTG module registers */
47 #define DA8XX_USB_GENERIC_RNDIS_EP_SIZE_REG(n) (0x50 + (((n) - 1) << 2))
77 * - not read/write INTRUSB/INTRUSBE (except during
79 * - use INTSET/INTCLR instead.
83 * da8xx_musb_enable - enable interrupts
87 void __iomem *reg_base = musb->ctrl_base; in da8xx_musb_enable()
91 mask = ((musb->epmask & DA8XX_USB_TX_EP_MASK) << DA8XX_INTR_TX_SHIFT) | in da8xx_musb_enable()
92 ((musb->epmask & DA8XX_USB_RX_EP_MASK) << DA8XX_INTR_RX_SHIFT) | in da8xx_musb_enable()
102 * da8xx_musb_disable - disable HDRC and flush interrupts
106 void __iomem *reg_base = musb->ctrl_base; in da8xx_musb_disable()
126 void __iomem *mregs = musb->mregs; in otg_timer()
131 * We poll because DaVinci's won't expose several OTG-critical in otg_timer()
135 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, in otg_timer()
136 usb_otg_state_string(musb->xceiv->otg->state)); in otg_timer()
138 spin_lock_irqsave(&musb->lock, flags); in otg_timer()
139 switch (musb->xceiv->otg->state) { in otg_timer()
142 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in otg_timer()
144 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in otg_timer()
146 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in otg_timer()
149 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in otg_timer()
156 * RTL seems to mis-handle session "start" otherwise (or in in otg_timer()
161 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in otg_timer()
164 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in otg_timer()
165 musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG, in otg_timer()
170 * There's no ID-changed IRQ, so we have no good way to tell in otg_timer()
171 * when to switch to the A-Default state machine (by setting in otg_timer()
176 * grounded and we're now in the A-Default state machine. in otg_timer()
184 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in otg_timer()
186 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in otg_timer()
191 spin_unlock_irqrestore(&musb->lock, flags); in otg_timer()
202 if (musb->is_active || (musb->a_wait_bcon == 0 && in da8xx_musb_try_idle()
203 musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { in da8xx_musb_try_idle()
204 dev_dbg(musb->controller, "%s active, deleting timer\n", in da8xx_musb_try_idle()
205 usb_otg_state_string(musb->xceiv->otg->state)); in da8xx_musb_try_idle()
206 del_timer(&musb->dev_timer); in da8xx_musb_try_idle()
211 if (time_after(last_timer, timeout) && timer_pending(&musb->dev_timer)) { in da8xx_musb_try_idle()
212 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n"); in da8xx_musb_try_idle()
217 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", in da8xx_musb_try_idle()
218 usb_otg_state_string(musb->xceiv->otg->state), in da8xx_musb_try_idle()
219 jiffies_to_msecs(timeout - jiffies)); in da8xx_musb_try_idle()
220 mod_timer(&musb->dev_timer, timeout); in da8xx_musb_try_idle()
225 dev_dbg(musb->controller, "resetting controller to recover from babble\n"); in da8xx_babble_recover()
226 musb_writel(musb->ctrl_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK); in da8xx_babble_recover()
233 void __iomem *reg_base = musb->ctrl_base; in da8xx_musb_interrupt()
238 spin_lock_irqsave(&musb->lock, flags); in da8xx_musb_interrupt()
245 /* Acknowledge and handle non-CPPI interrupts */ in da8xx_musb_interrupt()
251 dev_dbg(musb->controller, "USB IRQ %08x\n", status); in da8xx_musb_interrupt()
253 musb->int_rx = (status & DA8XX_INTR_RX_MASK) >> DA8XX_INTR_RX_SHIFT; in da8xx_musb_interrupt()
254 musb->int_tx = (status & DA8XX_INTR_TX_MASK) >> DA8XX_INTR_TX_SHIFT; in da8xx_musb_interrupt()
255 musb->int_usb = (status & DA8XX_INTR_USB_MASK) >> DA8XX_INTR_USB_SHIFT; in da8xx_musb_interrupt()
260 * switch appropriately between halves of the OTG state machine. in da8xx_musb_interrupt()
267 void __iomem *mregs = musb->mregs; in da8xx_musb_interrupt()
271 err = musb->int_usb & MUSB_INTR_VBUSERROR; in da8xx_musb_interrupt()
276 * means it's not uncommon for bus-powered devices in da8xx_musb_interrupt()
280 * seems to allow a better one: "re"-starting sessions in da8xx_musb_interrupt()
284 musb->int_usb &= ~MUSB_INTR_VBUSERROR; in da8xx_musb_interrupt()
285 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; in da8xx_musb_interrupt()
286 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in da8xx_musb_interrupt()
290 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in da8xx_musb_interrupt()
291 portstate(musb->port1_status |= USB_PORT_STAT_POWER); in da8xx_musb_interrupt()
292 del_timer(&musb->dev_timer); in da8xx_musb_interrupt()
293 } else if (!(musb->int_usb & MUSB_INTR_BABBLE)) { in da8xx_musb_interrupt()
298 * controller; otherwise, the host-mode flag is lost in da8xx_musb_interrupt()
302 musb->is_active = 0; in da8xx_musb_interrupt()
304 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in da8xx_musb_interrupt()
305 portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); in da8xx_musb_interrupt()
308 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", in da8xx_musb_interrupt()
310 usb_otg_state_string(musb->xceiv->otg->state), in da8xx_musb_interrupt()
316 if (musb->int_tx || musb->int_rx || musb->int_usb) in da8xx_musb_interrupt()
320 /* EOI needs to be written for the IRQ to be re-asserted. */ in da8xx_musb_interrupt()
325 if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) in da8xx_musb_interrupt()
326 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in da8xx_musb_interrupt()
328 spin_unlock_irqrestore(&musb->lock, flags); in da8xx_musb_interrupt()
335 struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); in da8xx_musb_set_mode()
349 return -EINVAL; in da8xx_musb_set_mode()
352 return phy_set_mode(glue->phy, phy_mode); in da8xx_musb_set_mode()
357 struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); in da8xx_musb_init()
358 void __iomem *reg_base = musb->ctrl_base; in da8xx_musb_init()
359 u32 rev; in da8xx_musb_init() local
360 int ret = -ENODEV; in da8xx_musb_init()
362 musb->mregs += DA8XX_MENTOR_CORE_OFFSET; in da8xx_musb_init()
364 ret = clk_prepare_enable(glue->clk); in da8xx_musb_init()
366 dev_err(glue->dev, "failed to enable clock\n"); in da8xx_musb_init()
371 rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG); in da8xx_musb_init()
372 if (!rev) { in da8xx_musb_init()
373 ret = -ENODEV; in da8xx_musb_init()
377 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); in da8xx_musb_init()
378 if (IS_ERR_OR_NULL(musb->xceiv)) { in da8xx_musb_init()
379 ret = -EPROBE_DEFER; in da8xx_musb_init()
383 timer_setup(&musb->dev_timer, otg_timer, 0); in da8xx_musb_init()
388 /* Start the on-chip PHY and its PLL. */ in da8xx_musb_init()
389 ret = phy_init(glue->phy); in da8xx_musb_init()
391 dev_err(glue->dev, "Failed to init phy.\n"); in da8xx_musb_init()
395 ret = phy_power_on(glue->phy); in da8xx_musb_init()
397 dev_err(glue->dev, "Failed to power on phy.\n"); in da8xx_musb_init()
404 pr_debug("DA8xx OTG revision %08x, control %02x\n", rev, in da8xx_musb_init()
407 musb->isr = da8xx_musb_interrupt; in da8xx_musb_init()
411 phy_exit(glue->phy); in da8xx_musb_init()
413 clk_disable_unprepare(glue->clk); in da8xx_musb_init()
419 struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); in da8xx_musb_exit()
421 del_timer_sync(&musb->dev_timer); in da8xx_musb_exit()
423 phy_power_off(glue->phy); in da8xx_musb_exit()
424 phy_exit(glue->phy); in da8xx_musb_exit()
425 clk_disable_unprepare(glue->clk); in da8xx_musb_exit()
427 usb_put_phy(musb->xceiv); in da8xx_musb_exit()
450 struct musb *musb = c->musb; in da8xx_dma_controller_callback()
451 void __iomem *reg_base = musb->ctrl_base; in da8xx_dma_controller_callback()
465 controller->dma_callback = da8xx_dma_controller_callback; in da8xx_dma_controller_create()
496 .name = "musb-hdrc",
508 OF_DEV_AUXDATA("ti,da830-cppi41", 0x01e01000, "cppi41-dmaengine",
515 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); in da8xx_probe()
519 struct device_node *np = pdev->dev.of_node; in da8xx_probe()
522 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); in da8xx_probe()
524 return -ENOMEM; in da8xx_probe()
526 clk = devm_clk_get(&pdev->dev, NULL); in da8xx_probe()
528 dev_err(&pdev->dev, "failed to get clock\n"); in da8xx_probe()
532 glue->phy = devm_phy_get(&pdev->dev, "usb-phy"); in da8xx_probe()
533 if (IS_ERR(glue->phy)) in da8xx_probe()
534 return dev_err_probe(&pdev->dev, PTR_ERR(glue->phy), in da8xx_probe()
537 glue->dev = &pdev->dev; in da8xx_probe()
538 glue->clk = clk; in da8xx_probe()
541 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in da8xx_probe()
543 return -ENOMEM; in da8xx_probe()
545 pdata->config = &da8xx_config; in da8xx_probe()
546 pdata->mode = musb_get_mode(&pdev->dev); in da8xx_probe()
547 pdata->power = get_vbus_power(&pdev->dev); in da8xx_probe()
550 pdata->platform_ops = &da8xx_ops; in da8xx_probe()
552 glue->usb_phy = usb_phy_generic_register(); in da8xx_probe()
553 ret = PTR_ERR_OR_ZERO(glue->usb_phy); in da8xx_probe()
555 dev_err(&pdev->dev, "failed to register usb_phy\n"); in da8xx_probe()
560 ret = of_platform_populate(pdev->dev.of_node, NULL, in da8xx_probe()
561 da8xx_auxdata_lookup, &pdev->dev); in da8xx_probe()
566 pinfo.parent = &pdev->dev; in da8xx_probe()
567 pinfo.res = pdev->resource; in da8xx_probe()
568 pinfo.num_res = pdev->num_resources; in da8xx_probe()
574 glue->musb = platform_device_register_full(&pinfo); in da8xx_probe()
575 ret = PTR_ERR_OR_ZERO(glue->musb); in da8xx_probe()
577 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); in da8xx_probe()
584 usb_phy_generic_unregister(glue->usb_phy); in da8xx_probe()
592 platform_device_unregister(glue->musb); in da8xx_remove()
593 usb_phy_generic_unregister(glue->usb_phy); in da8xx_remove()
602 ret = phy_power_off(glue->phy); in da8xx_suspend()
605 clk_disable_unprepare(glue->clk); in da8xx_suspend()
615 ret = clk_prepare_enable(glue->clk); in da8xx_resume()
618 return phy_power_on(glue->phy); in da8xx_resume()
627 .compatible = "ti,da830-musb",
638 .name = "musb-da8xx",
644 MODULE_DESCRIPTION("DA8xx/OMAP-L1x MUSB Glue Layer");