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

1 // SPDX-License-Identifier: GPL-2.0
4 * Texas Instruments AM35x "glue layer"
8 * Based on the DA8xx "glue layer" code.
9 * Copyright (c) 2008-2009, MontaVista Software, Inc. <source@mvista.com>
19 #include <linux/dma-mapping.h>
20 #include <linux/usb/usb_phy_generic.h>
21 #include <linux/platform_data/usb-omap.h>
28 /* USB 2.0 OTG module registers */
57 /* USB interrupt register bits */
79 * am35x_musb_enable - enable interrupts
83 void __iomem *reg_base = musb->ctrl_base; in am35x_musb_enable()
87 epmask = ((musb->epmask & AM35X_TX_EP_MASK) << AM35X_INTR_TX_SHIFT) | in am35x_musb_enable()
88 ((musb->epmask & AM35X_RX_EP_MASK) << AM35X_INTR_RX_SHIFT); in am35x_musb_enable()
99 * am35x_musb_disable - disable HDRC and flush interrupts
103 void __iomem *reg_base = musb->ctrl_base; in am35x_musb_disable()
123 void __iomem *mregs = musb->mregs; in otg_timer()
128 * We poll because AM35x's won't expose several OTG-critical in otg_timer()
132 dev_dbg(musb->controller, "Poll devctl %02x (%s)\n", devctl, in otg_timer()
133 usb_otg_state_string(musb->xceiv->otg->state)); in otg_timer()
135 spin_lock_irqsave(&musb->lock, flags); in otg_timer()
136 switch (musb->xceiv->otg->state) { in otg_timer()
139 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in otg_timer()
141 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in otg_timer()
143 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in otg_timer()
146 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in otg_timer()
151 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in otg_timer()
152 musb_writel(musb->ctrl_base, CORE_INTR_SRC_SET_REG, in otg_timer()
158 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in otg_timer()
160 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in otg_timer()
165 spin_unlock_irqrestore(&musb->lock, flags); in otg_timer()
176 if (musb->is_active || (musb->a_wait_bcon == 0 && in am35x_musb_try_idle()
177 musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON)) { in am35x_musb_try_idle()
178 dev_dbg(musb->controller, "%s active, deleting timer\n", in am35x_musb_try_idle()
179 usb_otg_state_string(musb->xceiv->otg->state)); in am35x_musb_try_idle()
180 del_timer(&musb->dev_timer); in am35x_musb_try_idle()
185 if (time_after(last_timer, timeout) && timer_pending(&musb->dev_timer)) { in am35x_musb_try_idle()
186 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring...\n"); in am35x_musb_try_idle()
191 dev_dbg(musb->controller, "%s inactive, starting idle timer for %u ms\n", in am35x_musb_try_idle()
192 usb_otg_state_string(musb->xceiv->otg->state), in am35x_musb_try_idle()
193 jiffies_to_msecs(timeout - jiffies)); in am35x_musb_try_idle()
194 mod_timer(&musb->dev_timer, timeout); in am35x_musb_try_idle()
200 void __iomem *reg_base = musb->ctrl_base; in am35x_musb_interrupt()
201 struct device *dev = musb->controller; in am35x_musb_interrupt()
203 struct omap_musb_board_data *data = plat->board_data; in am35x_musb_interrupt()
208 spin_lock_irqsave(&musb->lock, flags); in am35x_musb_interrupt()
216 musb->int_rx = in am35x_musb_interrupt()
218 musb->int_tx = in am35x_musb_interrupt()
222 /* Get usb core interrupts */ in am35x_musb_interrupt()
230 musb->int_usb = in am35x_musb_interrupt()
243 void __iomem *mregs = musb->mregs; in am35x_musb_interrupt()
247 err = musb->int_usb & MUSB_INTR_VBUSERROR; in am35x_musb_interrupt()
252 * means it's not uncommon for bus-powered devices in am35x_musb_interrupt()
256 * seems to allow a better one: "re"-starting sessions in am35x_musb_interrupt()
260 musb->int_usb &= ~MUSB_INTR_VBUSERROR; in am35x_musb_interrupt()
261 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; in am35x_musb_interrupt()
262 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in am35x_musb_interrupt()
266 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in am35x_musb_interrupt()
267 portstate(musb->port1_status |= USB_PORT_STAT_POWER); in am35x_musb_interrupt()
268 del_timer(&musb->dev_timer); in am35x_musb_interrupt()
270 musb->is_active = 0; in am35x_musb_interrupt()
272 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in am35x_musb_interrupt()
273 portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); in am35x_musb_interrupt()
276 /* NOTE: this must complete power-on within 100 ms. */ in am35x_musb_interrupt()
277 dev_dbg(musb->controller, "VBUS %s (%s)%s, devctl %02x\n", in am35x_musb_interrupt()
279 usb_otg_state_string(musb->xceiv->otg->state), in am35x_musb_interrupt()
286 if (musb->int_usb & MUSB_INTR_DISCONNECT) { in am35x_musb_interrupt()
287 musb->int_tx = 0; in am35x_musb_interrupt()
288 musb->int_rx = 0; in am35x_musb_interrupt()
291 if (musb->int_tx || musb->int_rx || musb->int_usb) in am35x_musb_interrupt()
295 /* EOI needs to be written for the IRQ to be re-asserted. */ in am35x_musb_interrupt()
298 if (data->clear_irq) in am35x_musb_interrupt()
299 data->clear_irq(); in am35x_musb_interrupt()
305 if (musb->xceiv->otg->state == OTG_STATE_B_IDLE) in am35x_musb_interrupt()
306 mod_timer(&musb->dev_timer, jiffies + POLL_SECONDS * HZ); in am35x_musb_interrupt()
308 spin_unlock_irqrestore(&musb->lock, flags); in am35x_musb_interrupt()
315 struct device *dev = musb->controller; in am35x_musb_set_mode()
317 struct omap_musb_board_data *data = plat->board_data; in am35x_musb_set_mode()
320 if (data->set_mode) in am35x_musb_set_mode()
321 data->set_mode(musb_mode); in am35x_musb_set_mode()
323 retval = -EIO; in am35x_musb_set_mode()
330 struct device *dev = musb->controller; in am35x_musb_init()
332 struct omap_musb_board_data *data = plat->board_data; in am35x_musb_init()
333 void __iomem *reg_base = musb->ctrl_base; in am35x_musb_init()
336 musb->mregs += USB_MENTOR_CORE_OFFSET; in am35x_musb_init()
341 return -ENODEV; in am35x_musb_init()
343 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); in am35x_musb_init()
344 if (IS_ERR_OR_NULL(musb->xceiv)) in am35x_musb_init()
345 return -EPROBE_DEFER; in am35x_musb_init()
347 timer_setup(&musb->dev_timer, otg_timer, 0); in am35x_musb_init()
350 if (data->reset) in am35x_musb_init()
351 data->reset(); in am35x_musb_init()
356 /* Start the on-chip PHY and its PLL. */ in am35x_musb_init()
357 if (data->set_phy_power) in am35x_musb_init()
358 data->set_phy_power(1); in am35x_musb_init()
362 musb->isr = am35x_musb_interrupt; in am35x_musb_init()
365 if (data->clear_irq) in am35x_musb_init()
366 data->clear_irq(); in am35x_musb_init()
373 struct device *dev = musb->controller; in am35x_musb_exit()
375 struct omap_musb_board_data *data = plat->board_data; in am35x_musb_exit()
377 del_timer_sync(&musb->dev_timer); in am35x_musb_exit()
379 /* Shutdown the on-chip PHY and its PLL. */ in am35x_musb_exit()
380 if (data->set_phy_power) in am35x_musb_exit()
381 data->set_phy_power(0); in am35x_musb_exit()
383 usb_put_phy(musb->xceiv); in am35x_musb_exit()
391 void __iomem *fifo = hw_ep->fifo; in am35x_read_fifo()
395 /* Read for 32bit-aligned destination address */ in am35x_read_fifo()
438 .name = "musb-hdrc",
445 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); in am35x_probe()
447 struct am35x_glue *glue; in am35x_probe() local
452 int ret = -ENOMEM; in am35x_probe()
454 glue = kzalloc(sizeof(*glue), GFP_KERNEL); in am35x_probe()
455 if (!glue) in am35x_probe()
458 phy_clk = clk_get(&pdev->dev, "fck"); in am35x_probe()
460 dev_err(&pdev->dev, "failed to get PHY clock\n"); in am35x_probe()
465 clk = clk_get(&pdev->dev, "ick"); in am35x_probe()
467 dev_err(&pdev->dev, "failed to get clock\n"); in am35x_probe()
474 dev_err(&pdev->dev, "failed to enable PHY clock\n"); in am35x_probe()
480 dev_err(&pdev->dev, "failed to enable clock\n"); in am35x_probe()
484 glue->dev = &pdev->dev; in am35x_probe()
485 glue->phy_clk = phy_clk; in am35x_probe()
486 glue->clk = clk; in am35x_probe()
488 pdata->platform_ops = &am35x_ops; in am35x_probe()
490 glue->phy = usb_phy_generic_register(); in am35x_probe()
491 if (IS_ERR(glue->phy)) { in am35x_probe()
492 ret = PTR_ERR(glue->phy); in am35x_probe()
495 platform_set_drvdata(pdev, glue); in am35x_probe()
498 pinfo.parent = &pdev->dev; in am35x_probe()
499 pinfo.res = pdev->resource; in am35x_probe()
500 pinfo.num_res = pdev->num_resources; in am35x_probe()
503 pinfo.fwnode = of_fwnode_handle(pdev->dev.of_node); in am35x_probe()
506 glue->musb = musb = platform_device_register_full(&pinfo); in am35x_probe()
509 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); in am35x_probe()
516 usb_phy_generic_unregister(glue->phy); in am35x_probe()
531 kfree(glue); in am35x_probe()
539 struct am35x_glue *glue = platform_get_drvdata(pdev); in am35x_remove() local
541 platform_device_unregister(glue->musb); in am35x_remove()
542 usb_phy_generic_unregister(glue->phy); in am35x_remove()
543 clk_disable(glue->clk); in am35x_remove()
544 clk_disable(glue->phy_clk); in am35x_remove()
545 clk_put(glue->clk); in am35x_remove()
546 clk_put(glue->phy_clk); in am35x_remove()
547 kfree(glue); in am35x_remove()
555 struct am35x_glue *glue = dev_get_drvdata(dev); in am35x_suspend() local
557 struct omap_musb_board_data *data = plat->board_data; in am35x_suspend()
559 /* Shutdown the on-chip PHY and its PLL. */ in am35x_suspend()
560 if (data->set_phy_power) in am35x_suspend()
561 data->set_phy_power(0); in am35x_suspend()
563 clk_disable(glue->phy_clk); in am35x_suspend()
564 clk_disable(glue->clk); in am35x_suspend()
571 struct am35x_glue *glue = dev_get_drvdata(dev); in am35x_resume() local
573 struct omap_musb_board_data *data = plat->board_data; in am35x_resume()
576 /* Start the on-chip PHY and its PLL. */ in am35x_resume()
577 if (data->set_phy_power) in am35x_resume()
578 data->set_phy_power(1); in am35x_resume()
580 ret = clk_enable(glue->phy_clk); in am35x_resume()
586 ret = clk_enable(glue->clk); in am35x_resume()
602 .name = "musb-am35x",
607 MODULE_DESCRIPTION("AM35x MUSB Glue Layer");