Lines Matching +full:need +full:- +full:phy +full:- +full:for +full:- +full:wake
1 // SPDX-License-Identifier: GPL-2.0
9 * - Driver assumes that interface to external host (main CPU) is
10 * configured for NOR FLASH interface instead of VLYNQ serial
24 #include <linux/dma-mapping.h>
32 struct platform_device *phy; member
41 * Checks the revision. We need to use the DMA register as 3.0 does not
42 * have correct versions for TUSB_PRCM_REV or TUSB_INT_CTRL_REV.
46 void __iomem *tbase = musb->ctrl_base; in tusb_get_revision()
63 void __iomem *tbase = musb->ctrl_base; in tusb_print_revision()
66 rev = musb->tusb_revision; in tusb_print_revision()
91 * Workaround for spontaneous WBUS wake-up issue #2 for tusb3.0.
92 * Disables power detection in PHY for the duration of idle.
96 void __iomem *tbase = musb->ctrl_base; in tusb_wbus_quirk()
109 dev_dbg(musb->controller, "Enabled tusb wbus quirk ctrl %08x ena %08x\n", in tusb_wbus_quirk()
118 dev_dbg(musb->controller, "Disabled tusb wbus quirk ctrl %08x ena %08x\n", in tusb_wbus_quirk()
143 * TUSB6010 doesn't allow 8-bit access; 16-bit access is the minimum.
174 * so both loading and unloading FIFOs need explicit byte counts.
184 for (i = 0; i < (len >> 2); i++) { in tusb_fifo_write_unaligned()
192 /* Write the rest 1 - 3 bytes to FIFO */ in tusb_fifo_write_unaligned()
206 for (i = 0; i < (len >> 2); i++) { in tusb_fifo_read_unaligned()
214 /* Read the rest 1 - 3 bytes from FIFO */ in tusb_fifo_read_unaligned()
222 struct musb *musb = hw_ep->musb; in tusb_write_fifo()
223 void __iomem *ep_conf = hw_ep->conf; in tusb_write_fifo()
224 void __iomem *fifo = hw_ep->fifo; in tusb_write_fifo()
225 u8 epnum = hw_ep->epnum; in tusb_write_fifo()
229 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n", in tusb_write_fifo()
241 /* Best case is 32bit-aligned destination address */ in tusb_write_fifo()
253 /* Cannot use writesw, fifo is 32-bit */ in tusb_write_fifo()
254 for (i = 0; i < (len >> 2); i++) { in tusb_write_fifo()
272 struct musb *musb = hw_ep->musb; in tusb_read_fifo()
273 void __iomem *ep_conf = hw_ep->conf; in tusb_read_fifo()
274 void __iomem *fifo = hw_ep->fifo; in tusb_read_fifo()
275 u8 epnum = hw_ep->epnum; in tusb_read_fifo()
277 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n", in tusb_read_fifo()
288 /* Best case is 32bit-aligned destination address */ in tusb_read_fifo()
300 /* Cannot use readsw, fifo is 32-bit */ in tusb_read_fifo()
301 for (i = 0; i < (len >> 2); i++) { in tusb_read_fifo()
320 * at most mA current to be drawn from VBUS during a Default-B session
321 * (that is, while VBUS exceeds 4.4V). In Default-A (including pure host
322 * mode), or low power Default-B sessions, something else supplies power.
328 void __iomem *tbase = musb->ctrl_base; in tusb_draw_power()
332 * (measured on one board) for things other than tps and tusb. in tusb_draw_power()
334 * Boards sharing the CPU clock with CLKIN will need to prevent in tusb_draw_power()
338 * The actual current usage would be very board-specific. For now, in tusb_draw_power()
339 * it's simpler to just use an aggregate (also board-specific). in tusb_draw_power()
341 if (x->otg->default_a || mA < (musb->min_power << 1)) in tusb_draw_power()
346 musb->is_bus_powered = 1; in tusb_draw_power()
349 musb->is_bus_powered = 0; in tusb_draw_power()
354 dev_dbg(musb->controller, "draw max %d mA VBUS\n", mA); in tusb_draw_power()
358 /* workaround for issue 13: change clock during chip idle
364 void __iomem *tbase = musb->ctrl_base; in tusb_set_clock_source()
371 * 1 = PHY 60 MHz (internal PLL) in tusb_set_clock_source()
384 * Idle TUSB6010 until next wake-up event; NOR access always wakes.
387 * events. SW_EN for voltage is handled separately.
391 void __iomem *tbase = musb->ctrl_base; in tusb_allow_idle()
395 && (musb->tusb_revision == TUSB_REV_30)) in tusb_allow_idle()
420 dev_dbg(musb->controller, "idle, wake on %02x\n", wakeup_enables); in tusb_allow_idle()
428 void __iomem *tbase = musb->ctrl_base; in tusb_musb_vbus_status()
435 /* Temporarily enable VBUS detection if it was disabled for in tusb_musb_vbus_status()
458 spin_lock_irqsave(&musb->lock, flags); in musb_do_idle()
460 switch (musb->xceiv->otg->state) { in musb_do_idle()
462 if ((musb->a_wait_bcon != 0) in musb_do_idle()
463 && (musb->idle_timeout == 0 in musb_do_idle()
464 || time_after(jiffies, musb->idle_timeout))) { in musb_do_idle()
465 dev_dbg(musb->controller, "Nothing connected %s, turning off VBUS\n", in musb_do_idle()
466 usb_otg_state_string(musb->xceiv->otg->state)); in musb_do_idle()
476 if (!musb->is_active) { in musb_do_idle()
480 if (is_host_active(musb) && (musb->port1_status >> 16)) in musb_do_idle()
483 if (!musb->gadget_driver) { in musb_do_idle()
494 spin_unlock_irqrestore(&musb->lock, flags); in musb_do_idle()
503 * register access to TUSB6010 because of NOR flash wake-up.
519 if (musb->is_active || ((musb->a_wait_bcon == 0) in tusb_musb_try_idle()
520 && (musb->xceiv->otg->state == OTG_STATE_A_WAIT_BCON))) { in tusb_musb_try_idle()
521 dev_dbg(musb->controller, "%s active, deleting timer\n", in tusb_musb_try_idle()
522 usb_otg_state_string(musb->xceiv->otg->state)); in tusb_musb_try_idle()
523 del_timer(&musb->dev_timer); in tusb_musb_try_idle()
529 if (!timer_pending(&musb->dev_timer)) in tusb_musb_try_idle()
532 dev_dbg(musb->controller, "Longer idle timer already pending, ignoring\n"); in tusb_musb_try_idle()
538 dev_dbg(musb->controller, "%s inactive, for idle timer for %lu ms\n", in tusb_musb_try_idle()
539 usb_otg_state_string(musb->xceiv->otg->state), in tusb_musb_try_idle()
540 (unsigned long)jiffies_to_msecs(timeout - jiffies)); in tusb_musb_try_idle()
541 mod_timer(&musb->dev_timer, timeout); in tusb_musb_try_idle()
553 void __iomem *tbase = musb->ctrl_base; in tusb_musb_set_vbus()
556 struct usb_otg *otg = musb->xceiv->otg; in tusb_musb_set_vbus()
565 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in tusb_musb_set_vbus()
569 otg->default_a = 1; in tusb_musb_set_vbus()
570 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VRISE; in tusb_musb_set_vbus()
583 switch (musb->xceiv->otg->state) { in tusb_musb_set_vbus()
586 musb->xceiv->otg->state = OTG_STATE_A_WAIT_VFALL; in tusb_musb_set_vbus()
589 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in tusb_musb_set_vbus()
592 musb->xceiv->otg->state = OTG_STATE_A_IDLE; in tusb_musb_set_vbus()
594 musb->is_active = 0; in tusb_musb_set_vbus()
595 otg->default_a = 1; in tusb_musb_set_vbus()
598 musb->is_active = 0; in tusb_musb_set_vbus()
599 otg->default_a = 0; in tusb_musb_set_vbus()
600 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in tusb_musb_set_vbus()
612 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in tusb_musb_set_vbus()
614 dev_dbg(musb->controller, "VBUS %s, devctl %02x otg %3x conf %08x prcm %08x\n", in tusb_musb_set_vbus()
615 usb_otg_state_string(musb->xceiv->otg->state), in tusb_musb_set_vbus()
616 musb_readb(musb->mregs, MUSB_DEVCTL), in tusb_musb_set_vbus()
625 * Note that if a mini-A cable is plugged in the ID line will stay down as
626 * the weak ID pull-up is not able to pull the ID up.
630 void __iomem *tbase = musb->ctrl_base; in tusb_musb_set_mode()
640 case MUSB_HOST: /* Disable PHY ID detect, ground ID */ in tusb_musb_set_mode()
646 case MUSB_PERIPHERAL: /* Disable PHY ID detect, keep ID pull-up on */ in tusb_musb_set_mode()
651 case MUSB_OTG: /* Use PHY ID detection */ in tusb_musb_set_mode()
658 dev_dbg(musb->controller, "Trying to set mode %i\n", musb_mode); in tusb_musb_set_mode()
659 return -EINVAL; in tusb_musb_set_mode()
671 INFO("Cannot be peripheral with mini-A cable " in tusb_musb_set_mode()
682 struct usb_otg *otg = musb->xceiv->otg; in tusb_otg_ints()
689 dev_dbg(musb->controller, "Default-%c\n", default_a ? 'A' : 'B'); in tusb_otg_ints()
690 otg->default_a = default_a; in tusb_otg_ints()
701 /* B-dev state machine: no vbus ~= disconnect */ in tusb_otg_ints()
702 if (!otg->default_a) { in tusb_otg_ints()
704 musb->port1_status &= in tusb_otg_ints()
713 dev_dbg(musb->controller, "Forcing disconnect (no interrupt)\n"); in tusb_otg_ints()
714 if (musb->xceiv->otg->state != OTG_STATE_B_IDLE) { in tusb_otg_ints()
716 musb->xceiv->otg->state = OTG_STATE_B_IDLE; in tusb_otg_ints()
717 musb->int_usb |= MUSB_INTR_DISCONNECT; in tusb_otg_ints()
719 musb->is_active = 0; in tusb_otg_ints()
721 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", in tusb_otg_ints()
722 usb_otg_state_string(musb->xceiv->otg->state), otg_stat); in tusb_otg_ints()
724 schedule_delayed_work(&musb->irq_work, 0); in tusb_otg_ints()
726 } else /* A-dev state machine */ { in tusb_otg_ints()
727 dev_dbg(musb->controller, "vbus change, %s, otg %03x\n", in tusb_otg_ints()
728 usb_otg_state_string(musb->xceiv->otg->state), otg_stat); in tusb_otg_ints()
730 switch (musb->xceiv->otg->state) { in tusb_otg_ints()
732 dev_dbg(musb->controller, "Got SRP, turning on VBUS\n"); in tusb_otg_ints()
735 /* CONNECT can wake if a_wait_bcon is set */ in tusb_otg_ints()
736 if (musb->a_wait_bcon != 0) in tusb_otg_ints()
737 musb->is_active = 0; in tusb_otg_ints()
739 musb->is_active = 1; in tusb_otg_ints()
742 * OPT FS A TD.4.6 needs few seconds for in tusb_otg_ints()
749 /* ignore; A-session-valid < VBUS_VALID/2, in tusb_otg_ints()
757 if (musb->vbuserr_retry) { in tusb_otg_ints()
758 musb->vbuserr_retry--; in tusb_otg_ints()
761 musb->vbuserr_retry in tusb_otg_ints()
776 dev_dbg(musb->controller, "%s timer, %03x\n", in tusb_otg_ints()
777 usb_otg_state_string(musb->xceiv->otg->state), otg_stat); in tusb_otg_ints()
779 switch (musb->xceiv->otg->state) { in tusb_otg_ints()
781 /* VBUS has probably been valid for a while now, in tusb_otg_ints()
784 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in tusb_otg_ints()
788 dev_dbg(musb->controller, "devctl %02x\n", devctl); in tusb_otg_ints()
791 musb->xceiv->otg->state = OTG_STATE_A_WAIT_BCON; in tusb_otg_ints()
792 musb->is_active = 0; in tusb_otg_ints()
794 + msecs_to_jiffies(musb->a_wait_bcon); in tusb_otg_ints()
802 if (musb->a_wait_bcon != 0) in tusb_otg_ints()
804 + msecs_to_jiffies(musb->a_wait_bcon); in tusb_otg_ints()
814 schedule_delayed_work(&musb->irq_work, 0); in tusb_otg_ints()
822 void __iomem *tbase = musb->ctrl_base; in tusb_musb_interrupt()
826 spin_lock_irqsave(&musb->lock, flags); in tusb_musb_interrupt()
833 dev_dbg(musb->controller, "TUSB IRQ %08x\n", int_src); in tusb_musb_interrupt()
835 musb->int_usb = (u8) int_src; in tusb_musb_interrupt()
837 /* Acknowledge wake-up source interrupts */ in tusb_musb_interrupt()
842 if (musb->tusb_revision == TUSB_REV_30) in tusb_musb_interrupt()
845 /* there are issues re-locking the PLL on wakeup ... */ in tusb_musb_interrupt()
848 for (i = 0xf7f7f7; i > 0xf7f7f7 - 1000; i--) { in tusb_musb_interrupt()
854 dev_dbg(musb->controller, "TUSB NOR not ready\n"); in tusb_musb_interrupt()
863 musb->is_active = 1; in tusb_musb_interrupt()
864 schedule_delayed_work(&musb->irq_work, 0); in tusb_musb_interrupt()
866 dev_dbg(musb->controller, "wake %sactive %02x\n", in tusb_musb_interrupt()
867 musb->is_active ? "" : "in", reg); in tusb_musb_interrupt()
873 del_timer(&musb->dev_timer); in tusb_musb_interrupt()
882 * Just clear the DMA interrupt if it comes as the completion for both in tusb_musb_interrupt()
888 dev_dbg(musb->controller, "DMA IRQ %08x\n", dma_src); in tusb_musb_interrupt()
897 musb->int_rx = (((musb_src >> 16) & 0xffff) << 1); in tusb_musb_interrupt()
898 musb->int_tx = (musb_src & 0xffff); in tusb_musb_interrupt()
900 musb->int_rx = 0; in tusb_musb_interrupt()
901 musb->int_tx = 0; in tusb_musb_interrupt()
907 /* Acknowledge TUSB interrupts. Clear only non-reserved bits */ in tusb_musb_interrupt()
914 spin_unlock_irqrestore(&musb->lock, flags); in tusb_musb_interrupt()
924 * - Check what is unnecessary in MGC_HdrcStart()
928 void __iomem *tbase = musb->ctrl_base; in tusb_musb_enable()
947 /* Only 0 clock cycles for minimum interrupt de-assertion time and in tusb_musb_enable()
952 irq_set_irq_type(musb->nIrq, IRQ_TYPE_LEVEL_LOW); in tusb_musb_enable()
954 /* maybe force into the Default-A OTG state machine */ in tusb_musb_enable()
972 void __iomem *tbase = musb->ctrl_base; in tusb_musb_disable()
982 del_timer(&musb->dev_timer); in tusb_musb_disable()
993 * Note: Settings optimized for OMAP24xx
997 void __iomem *tbase = musb->ctrl_base; in tusb_setup_cpu_interface()
1001 * Don't disable GPIO[7:6] as they are needed for wake-up. in tusb_setup_cpu_interface()
1012 * de-assertion time 2 system clocks p 62 */ in tusb_setup_cpu_interface()
1018 /* Set 0 wait count for synchronous burst access */ in tusb_setup_cpu_interface()
1024 void __iomem *tbase = musb->ctrl_base; in tusb_musb_start()
1029 if (musb->board_set_power) in tusb_musb_start()
1030 ret = musb->board_set_power(1); in tusb_musb_start()
1036 spin_lock_irqsave(&musb->lock, flags); in tusb_musb_start()
1044 musb->tusb_revision = tusb_get_revision(musb); in tusb_musb_start()
1046 if (musb->tusb_revision < 2) { in tusb_musb_start()
1048 musb->tusb_revision); in tusb_musb_start()
1052 /* The uint bit for "USB non-PDR interrupt enable" has to be 1 when in tusb_musb_start()
1056 /* Select PHY free running 60MHz as a system clock */ in tusb_musb_start()
1059 /* VBus valid timer 1us, disable DFT/Debug and VLYNQ clocks for in tusb_musb_start()
1079 spin_unlock_irqrestore(&musb->lock, flags); in tusb_musb_start()
1084 spin_unlock_irqrestore(&musb->lock, flags); in tusb_musb_start()
1086 if (musb->board_set_power) in tusb_musb_start()
1087 musb->board_set_power(0); in tusb_musb_start()
1089 return -ENODEV; in tusb_musb_start()
1099 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); in tusb_musb_init()
1100 if (IS_ERR_OR_NULL(musb->xceiv)) in tusb_musb_init()
1101 return -EPROBE_DEFER; in tusb_musb_init()
1103 pdev = to_platform_device(musb->controller); in tusb_musb_init()
1105 /* dma address for async dma */ in tusb_musb_init()
1109 ret = -ENODEV; in tusb_musb_init()
1112 musb->async = mem->start; in tusb_musb_init()
1114 /* dma address for sync dma */ in tusb_musb_init()
1118 ret = -ENODEV; in tusb_musb_init()
1121 musb->sync = mem->start; in tusb_musb_init()
1123 sync = ioremap(mem->start, resource_size(mem)); in tusb_musb_init()
1125 pr_debug("ioremap for sync failed\n"); in tusb_musb_init()
1126 ret = -ENOMEM; in tusb_musb_init()
1129 musb->sync_va = sync; in tusb_musb_init()
1134 musb->mregs += TUSB_BASE_OFFSET; in tusb_musb_init()
1142 musb->isr = tusb_musb_interrupt; in tusb_musb_init()
1144 musb->xceiv->set_power = tusb_draw_power; in tusb_musb_init()
1147 timer_setup(&musb->dev_timer, musb_do_idle, 0); in tusb_musb_init()
1154 usb_put_phy(musb->xceiv); in tusb_musb_init()
1161 del_timer_sync(&musb->dev_timer); in tusb_musb_exit()
1164 if (musb->board_set_power) in tusb_musb_exit()
1165 musb->board_set_power(0); in tusb_musb_exit()
1167 iounmap(musb->sync_va); in tusb_musb_exit()
1169 usb_put_phy(musb->xceiv); in tusb_musb_exit()
1201 .name = "musb-hdrc",
1209 struct musb_hdrc_platform_data *pdata = dev_get_platdata(&pdev->dev); in tusb_probe()
1215 glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); in tusb_probe()
1217 return -ENOMEM; in tusb_probe()
1219 glue->dev = &pdev->dev; in tusb_probe()
1221 pdata->platform_ops = &tusb_ops; in tusb_probe()
1229 musb_resources[0].name = pdev->resource[0].name; in tusb_probe()
1230 musb_resources[0].start = pdev->resource[0].start; in tusb_probe()
1231 musb_resources[0].end = pdev->resource[0].end; in tusb_probe()
1232 musb_resources[0].flags = pdev->resource[0].flags; in tusb_probe()
1234 musb_resources[1].name = pdev->resource[1].name; in tusb_probe()
1235 musb_resources[1].start = pdev->resource[1].start; in tusb_probe()
1236 musb_resources[1].end = pdev->resource[1].end; in tusb_probe()
1237 musb_resources[1].flags = pdev->resource[1].flags; in tusb_probe()
1239 musb_resources[2].name = pdev->resource[2].name; in tusb_probe()
1240 musb_resources[2].start = pdev->resource[2].start; in tusb_probe()
1241 musb_resources[2].end = pdev->resource[2].end; in tusb_probe()
1242 musb_resources[2].flags = pdev->resource[2].flags; in tusb_probe()
1245 pinfo.parent = &pdev->dev; in tusb_probe()
1251 glue->musb = musb = platform_device_register_full(&pinfo); in tusb_probe()
1254 dev_err(&pdev->dev, "failed to register musb device: %d\n", ret); in tusb_probe()
1265 platform_device_unregister(glue->musb); in tusb_remove()
1266 usb_phy_generic_unregister(glue->phy); in tusb_remove()
1275 .name = "musb-tusb",