Lines Matching +full:dual +full:- +full:expiration

1 // SPDX-License-Identifier: GPL-2.0
3 * TUSB6010 USB 2.0 OTG Dual Role controller
9 * - Driver assumes that interface to external host (main CPU) is
27 #include <linux/dma-mapping.h>
51 void __iomem *tbase = musb->ctrl_base; in tusb_get_revision()
68 void __iomem *tbase = musb->ctrl_base; in tusb_print_revision()
71 rev = musb->tusb_revision; in tusb_print_revision()
96 * Workaround for spontaneous WBUS wake-up issue #2 for tusb3.0.
101 void __iomem *tbase = musb->ctrl_base; in tusb_wbus_quirk()
114 dev_dbg(musb->controller, "Enabled tusb wbus quirk ctrl %08x ena %08x\n", in tusb_wbus_quirk()
123 dev_dbg(musb->controller, "Disabled tusb wbus quirk ctrl %08x ena %08x\n", in tusb_wbus_quirk()
148 * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
197 /* Write the rest 1 - 3 bytes to FIFO */ in tusb_fifo_write_unaligned()
219 /* Read the rest 1 - 3 bytes from FIFO */ in tusb_fifo_read_unaligned()
227 struct musb *musb = hw_ep->musb; in tusb_write_fifo()
228 void __iomem *ep_conf = hw_ep->conf; in tusb_write_fifo()
229 void __iomem *fifo = hw_ep->fifo; in tusb_write_fifo()
230 u8 epnum = hw_ep->epnum; in tusb_write_fifo()
234 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n", in tusb_write_fifo()
246 /* Best case is 32bit-aligned destination address */ in tusb_write_fifo()
258 /* Cannot use writesw, fifo is 32-bit */ in tusb_write_fifo()
277 struct musb *musb = hw_ep->musb; in tusb_read_fifo()
278 void __iomem *ep_conf = hw_ep->conf; in tusb_read_fifo()
279 void __iomem *fifo = hw_ep->fifo; in tusb_read_fifo()
280 u8 epnum = hw_ep->epnum; in tusb_read_fifo()
282 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n", in tusb_read_fifo()
293 /* Best case is 32bit-aligned destination address */ in tusb_read_fifo()
305 /* Cannot use readsw, fifo is 32-bit */ in tusb_read_fifo()
325 * at most mA current to be drawn from VBUS during a Default-B session
326 * (that is, while VBUS exceeds 4.4V). In Default-A (including pure host
327 * mode), or low power Default-B sessions, something else supplies power.
333 void __iomem *tbase = musb->ctrl_base; in tusb_draw_power()
343 * The actual current usage would be very board-specific. For now, in tusb_draw_power()
344 * it's simpler to just use an aggregate (also board-specific). in tusb_draw_power()
346 if (x->otg->default_a || mA < (musb->min_power << 1)) in tusb_draw_power()
351 musb->is_bus_powered = 1; in tusb_draw_power()
354 musb->is_bus_powered = 0; in tusb_draw_power()
359 dev_dbg(musb->controller, "draw max %d mA VBUS\n", mA); in tusb_draw_power()
369 void __iomem *tbase = musb->ctrl_base; in tusb_set_clock_source()
389 * Idle TUSB6010 until next wake-up event; NOR access always wakes.
396 void __iomem *tbase = musb->ctrl_base; in tusb_allow_idle()
400 && (musb->tusb_revision == TUSB_REV_30)) in tusb_allow_idle()
425 dev_dbg(musb->controller, "idle, wake on %02x\n", wakeup_enables); in tusb_allow_idle()
433 void __iomem *tbase = musb->ctrl_base; in tusb_musb_vbus_status()
463 spin_lock_irqsave(&musb->lock, flags); in musb_do_idle()
465 switch (musb->xceiv->otg->state) { in musb_do_idle()
467 if ((musb->a_wait_bcon != 0) in musb_do_idle()
468 && (musb->idle_timeout == 0 in musb_do_idle()
469 || time_after(jiffies, musb->idle_timeout))) { in musb_do_idle()
470 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", in musb_do_idle()
471 usb_otg_state_string(musb->xceiv->otg->state)); in musb_do_idle()
481 if (!musb->is_active) { in musb_do_idle()
485 if (is_host_active(musb) && (musb->port1_status >> 16)) in musb_do_idle()
488 if (!musb->gadget_driver) { in musb_do_idle()
499 spin_unlock_irqrestore(&musb->lock, flags); in musb_do_idle()
508 * register access to TUSB6010 because of NOR flash wake-up.
524 if (musb->is_active || ((musb->a_wait_bcon == 0) in tusb_musb_try_idle()
525 && (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON))) { in tusb_musb_try_idle()
526 dev_dbg(musb->controller, "%s active, deleting timer\n", in tusb_musb_try_idle()
527 usb_otg_state_string(musb->xceiv->otg->state)); in tusb_musb_try_idle()
528 del_timer(&musb->dev_timer); in tusb_musb_try_idle()
534 if (!timer_pending(&musb->dev_timer)) in tusb_musb_try_idle()
537 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n"); in tusb_musb_try_idle()
543 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", in tusb_musb_try_idle()
544 usb_otg_state_string(musb->xceiv->otg->state), in tusb_musb_try_idle()
545 (unsigned long)jiffies_to_msecs(timeout - jiffies)); in tusb_musb_try_idle()
546 mod_timer(&musb->dev_timer, timeout); in tusb_musb_try_idle()
558 void __iomem *tbase = musb->ctrl_base; in tusb_musb_set_vbus()
561 struct usb_otg *otg = musb->xceiv->otg; in tusb_musb_set_vbus()
570 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in tusb_musb_set_vbus()
574 otg->default_a = 1; in tusb_musb_set_vbus()
575 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in tusb_musb_set_vbus()
588 switch (musb->xceiv->otg->state) { in tusb_musb_set_vbus()
591 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; in tusb_musb_set_vbus()
594 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in tusb_musb_set_vbus()
597 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in tusb_musb_set_vbus()
599 musb->is_active = 0; in tusb_musb_set_vbus()
600 otg->default_a = 1; in tusb_musb_set_vbus()
603 musb->is_active = 0; in tusb_musb_set_vbus()
604 otg->default_a = 0; in tusb_musb_set_vbus()
605 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in tusb_musb_set_vbus()
617 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in tusb_musb_set_vbus()
619 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", in tusb_musb_set_vbus()
620 usb_otg_state_string(musb->xceiv->otg->state), in tusb_musb_set_vbus()
621 musb_readb(musb->mregs, MUSB_DEVCTL), in tusb_musb_set_vbus()
630 * Note that if a mini-A cable is plugged in the ID line will stay down as
631 * the weak ID pull-up is not able to pull the ID up.
635 void __iomem *tbase = musb->ctrl_base; in tusb_musb_set_mode()
651 case MUSB_PERIPHERAL: /* Disable PHY ID detect, keep ID pull-up on */ in tusb_musb_set_mode()
663 dev_dbg(musb->controller, "Trying to set mode %i\n", musb_mode); in tusb_musb_set_mode()
664 return -EINVAL; in tusb_musb_set_mode()
676 INFO("Cannot be peripheral with mini-A cable " in tusb_musb_set_mode()
687 struct usb_otg *otg = musb->xceiv->otg; in tusb_otg_ints()
694 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B'); in tusb_otg_ints()
695 otg->default_a = default_a; in tusb_otg_ints()
706 /* B-dev state machine: no vbus ~= disconnect */ in tusb_otg_ints()
707 if (!otg->default_a) { in tusb_otg_ints()
709 musb->port1_status &= in tusb_otg_ints()
718 dev_dbg(musb->controller, "Forcing disconnect (no interrupt)\n"); in tusb_otg_ints()
719 if (musb->xceiv->otg->state != OTG_STATE_B_IDLE) { in tusb_otg_ints()
721 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in tusb_otg_ints()
722 musb->int_usb |= MUSB_INTR_DISCONNECT; in tusb_otg_ints()
724 musb->is_active = 0; in tusb_otg_ints()
726 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", in tusb_otg_ints()
727 usb_otg_state_string(musb->xceiv->otg->state), otg_stat); in tusb_otg_ints()
729 schedule_delayed_work(&musb->irq_work, 0); in tusb_otg_ints()
731 } else /* A-dev state machine */ { in tusb_otg_ints()
732 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", in tusb_otg_ints()
733 usb_otg_state_string(musb->xceiv->otg->state), otg_stat); in tusb_otg_ints()
735 switch (musb->xceiv->otg->state) { in tusb_otg_ints()
737 dev_dbg(musb->controller, "Got SRP, turning on VBUS\n"); in tusb_otg_ints()
741 if (musb->a_wait_bcon != 0) in tusb_otg_ints()
742 musb->is_active = 0; in tusb_otg_ints()
744 musb->is_active = 1; in tusb_otg_ints()
754 /* ignore; A-session-valid < VBUS_VALID/2, in tusb_otg_ints()
762 if (musb->vbuserr_retry) { in tusb_otg_ints()
763 musb->vbuserr_retry--; in tusb_otg_ints()
766 musb->vbuserr_retry in tusb_otg_ints()
777 /* OTG timer expiration */ in tusb_otg_ints()
781 dev_dbg(musb->controller, "%s timer, %03x\n", in tusb_otg_ints()
782 usb_otg_state_string(musb->xceiv->otg->state), otg_stat); in tusb_otg_ints()
784 switch (musb->xceiv->otg->state) { in tusb_otg_ints()
789 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in tusb_otg_ints()
793 dev_dbg(musb->controller, "devctl %02x\n", devctl); in tusb_otg_ints()
796 musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; in tusb_otg_ints()
797 musb->is_active = 0; in tusb_otg_ints()
799 + msecs_to_jiffies(musb->a_wait_bcon); in tusb_otg_ints()
807 if (musb->a_wait_bcon != 0) in tusb_otg_ints()
809 + msecs_to_jiffies(musb->a_wait_bcon); in tusb_otg_ints()
819 schedule_delayed_work(&musb->irq_work, 0); in tusb_otg_ints()
827 void __iomem *tbase = musb->ctrl_base; in tusb_musb_interrupt()
831 spin_lock_irqsave(&musb->lock, flags); in tusb_musb_interrupt()
838 dev_dbg(musb->controller, "TUSB IRQ %08x\n", int_src); in tusb_musb_interrupt()
840 musb->int_usb = (u8) int_src; in tusb_musb_interrupt()
842 /* Acknowledge wake-up source interrupts */ in tusb_musb_interrupt()
847 if (musb->tusb_revision == TUSB_REV_30) in tusb_musb_interrupt()
850 /* there are issues re-locking the PLL on wakeup ... */ in tusb_musb_interrupt()
853 for (i = 0xf7f7f7; i > 0xf7f7f7 - 1000; i--) { in tusb_musb_interrupt()
859 dev_dbg(musb->controller, "TUSB NOR not ready\n"); in tusb_musb_interrupt()
868 musb->is_active = 1; in tusb_musb_interrupt()
869 schedule_delayed_work(&musb->irq_work, 0); in tusb_musb_interrupt()
871 dev_dbg(musb->controller, "wake %sactive %02x\n", in tusb_musb_interrupt()
872 musb->is_active ? "" : "in", reg); in tusb_musb_interrupt()
878 del_timer(&musb->dev_timer); in tusb_musb_interrupt()
893 dev_dbg(musb->controller, "DMA IRQ %08x\n", dma_src); in tusb_musb_interrupt()
902 musb->int_rx = (((musb_src >> 16) & 0xffff) << 1); in tusb_musb_interrupt()
903 musb->int_tx = (musb_src & 0xffff); in tusb_musb_interrupt()
905 musb->int_rx = 0; in tusb_musb_interrupt()
906 musb->int_tx = 0; in tusb_musb_interrupt()
912 /* Acknowledge TUSB interrupts. Clear only non-reserved bits */ in tusb_musb_interrupt()
919 spin_unlock_irqrestore(&musb->lock, flags); in tusb_musb_interrupt()
929 * - Check what is unnecessary in MGC_HdrcStart()
933 void __iomem *tbase = musb->ctrl_base; in tusb_musb_enable()
952 /* Only 0 clock cycles for minimum interrupt de-assertion time and in tusb_musb_enable()
957 irq_set_irq_type(musb->nIrq, IRQ_TYPE_LEVEL_LOW); in tusb_musb_enable()
959 /* maybe force into the Default-A OTG state machine */ in tusb_musb_enable()
977 void __iomem *tbase = musb->ctrl_base; in tusb_musb_disable()
987 del_timer(&musb->dev_timer); in tusb_musb_disable()
1002 void __iomem *tbase = musb->ctrl_base; in tusb_setup_cpu_interface()
1006 * Don't disable GPIO[7:6] as they are needed for wake-up. in tusb_setup_cpu_interface()
1017 * de-assertion time 2 system clocks p 62 */ in tusb_setup_cpu_interface()
1029 struct tusb6010_glue *glue = dev_get_drvdata(musb->controller->parent); in tusb_musb_start()
1030 void __iomem *tbase = musb->ctrl_base; in tusb_musb_start()
1040 gpiod_set_value(glue->enable, 1); in tusb_musb_start()
1044 glue->intpin); in tusb_musb_start()
1050 spin_lock_irqsave(&musb->lock, flags); in tusb_musb_start()
1058 musb->tusb_revision = tusb_get_revision(musb); in tusb_musb_start()
1060 if (musb->tusb_revision < 2) { in tusb_musb_start()
1062 musb->tusb_revision); in tusb_musb_start()
1066 /* The uint bit for "USB non-PDR interrupt enable" has to be 1 when in tusb_musb_start()
1093 spin_unlock_irqrestore(&musb->lock, flags); in tusb_musb_start()
1098 spin_unlock_irqrestore(&musb->lock, flags); in tusb_musb_start()
1100 gpiod_set_value(glue->enable, 0); in tusb_musb_start()
1103 return -ENODEV; in tusb_musb_start()
1113 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); in tusb_musb_init()
1114 if (IS_ERR_OR_NULL(musb->xceiv)) in tusb_musb_init()
1115 return -EPROBE_DEFER; in tusb_musb_init()
1117 pdev = to_platform_device(musb->controller); in tusb_musb_init()
1123 ret = -ENODEV; in tusb_musb_init()
1126 musb->async = mem->start; in tusb_musb_init()
1132 ret = -ENODEV; in tusb_musb_init()
1135 musb->sync = mem->start; in tusb_musb_init()
1137 sync = ioremap(mem->start, resource_size(mem)); in tusb_musb_init()
1140 ret = -ENOMEM; in tusb_musb_init()
1143 musb->sync_va = sync; in tusb_musb_init()
1148 musb->mregs += TUSB_BASE_OFFSET; in tusb_musb_init()
1156 musb->isr = tusb_musb_interrupt; in tusb_musb_init()
1158 musb->xceiv->set_power = tusb_draw_power; in tusb_musb_init()
1161 timer_setup(&musb->dev_timer, musb_do_idle, 0); in tusb_musb_init()
1168 usb_put_phy(musb->xceiv); in tusb_musb_init()
1175 struct tusb6010_glue *glue = dev_get_drvdata(musb->controller->parent); in tusb_musb_exit()
1177 del_timer_sync(&musb->dev_timer); in tusb_musb_exit()
1180 gpiod_set_value(glue->enable, 0); in tusb_musb_exit()
1183 iounmap(musb->sync_va); in tusb_musb_exit()
1185 usb_put_phy(musb->xceiv); in tusb_musb_exit()
1217 .name = "musb-hdrc",
1225 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); in tusb_probe()
1231 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); in tusb_probe()
1233 return -ENOMEM; in tusb_probe()
1235 glue->dev = &pdev->dev; in tusb_probe()
1237 glue->enable = devm_gpiod_get(glue->dev, "enable", GPIOD_OUT_LOW); in tusb_probe()
1238 if (IS_ERR(glue->enable)) in tusb_probe()
1239 return dev_err_probe(glue->dev, PTR_ERR(glue->enable), in tusb_probe()
1241 glue->intpin = devm_gpiod_get(glue->dev, "int", GPIOD_IN); in tusb_probe()
1242 if (IS_ERR(glue->intpin)) in tusb_probe()
1243 return dev_err_probe(glue->dev, PTR_ERR(glue->intpin), in tusb_probe()
1246 pdata->platform_ops = &tusb_ops; in tusb_probe()
1254 musb_resources[0].name = pdev->resource[0].name; in tusb_probe()
1255 musb_resources[0].start = pdev->resource[0].start; in tusb_probe()
1256 musb_resources[0].end = pdev->resource[0].end; in tusb_probe()
1257 musb_resources[0].flags = pdev->resource[0].flags; in tusb_probe()
1259 musb_resources[1].name = pdev->resource[1].name; in tusb_probe()
1260 musb_resources[1].start = pdev->resource[1].start; in tusb_probe()
1261 musb_resources[1].end = pdev->resource[1].end; in tusb_probe()
1262 musb_resources[1].flags = pdev->resource[1].flags; in tusb_probe()
1264 musb_resources[2] = DEFINE_RES_IRQ_NAMED(gpiod_to_irq(glue->intpin), "mc"); in tusb_probe()
1267 pinfo.parent = &pdev->dev; in tusb_probe()
1273 glue->musb = musb = platform_device_register_full(&pinfo); in tusb_probe()
1276 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); in tusb_probe()
1287 platform_device_unregister(glue->musb); in tusb_remove()
1288 usb_phy_generic_unregister(glue->phy); in tusb_remove()
1295 .name = "musb-tusb",