Lines Matching +full:hnp +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0
6 * Copyright (C) 2005-2006 by Texas Instruments
7 * Copyright (C) 2006-2007 Nokia Corporation
11 * Inventra (Multipoint) Dual-Role Controller Driver for Linux.
15 * in the works. These are normal Linux-USB controller drivers which
29 * - Lack of host-side transaction scheduling, for all transfer types.
35 * includes DaVinci EVM in a common non-OTG mode.
59 * - Kconfig for everything user-configurable
60 * - platform_device for addressing, irq, and platform_data
61 * - platform_data is mostly for board-specific information
77 #include <linux/dma-mapping.h>
84 #define TA_WAIT_BCON(m) max_t(int, (m)->a_wait_bcon, OTG_TIME_A_WAIT_BCON)
88 #define DRIVER_DESC "Inventra Dual-Role USB Controller Driver"
94 #define MUSB_DRIVER_NAME "musb-hdrc"
103 /*-------------------------------------------------------------------------*/
128 /*-------------------------------------------------------------------------*/
132 void __iomem *addr = phy->io_priv; in musb_ulpi_read()
138 pm_runtime_get_sync(phy->io_dev); in musb_ulpi_read()
157 ret = -ETIMEDOUT; in musb_ulpi_read()
169 pm_runtime_put(phy->io_dev); in musb_ulpi_read()
176 void __iomem *addr = phy->io_priv; in musb_ulpi_write()
182 pm_runtime_get_sync(phy->io_dev); in musb_ulpi_write()
197 ret = -ETIMEDOUT; in musb_ulpi_write()
207 pm_runtime_put(phy->io_dev); in musb_ulpi_write()
217 /*-------------------------------------------------------------------------*/
280 void __iomem *epio = qh->hw_ep->regs; in musb_default_get_toggle()
297 toggle = usb_gettoggle(urb->dev, qh->epnum, is_out); in musb_default_set_toggle()
316 struct musb *musb = hw_ep->musb; in musb_default_write_fifo()
317 void __iomem *fifo = hw_ep->fifo; in musb_default_write_fifo()
324 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n", in musb_default_write_fifo()
325 'T', hw_ep->epnum, fifo, len, src); in musb_default_write_fifo()
331 /* best case is 32bit-aligned source address */ in musb_default_write_fifo()
360 struct musb *musb = hw_ep->musb; in musb_default_read_fifo()
361 void __iomem *fifo = hw_ep->fifo; in musb_default_read_fifo()
366 dev_dbg(musb->controller, "%cX ep%d fifo %p count %d buf %p\n", in musb_default_read_fifo()
367 'R', hw_ep->epnum, fifo, len, dst); in musb_default_read_fifo()
373 /* best case is 32bit-aligned destination address */ in musb_default_read_fifo()
448 return hw_ep->musb->io.read_fifo(hw_ep, len, dst); in musb_read_fifo()
453 return hw_ep->musb->io.write_fifo(hw_ep, len, src); in musb_write_fifo()
458 return musb_readb(musb->mregs, MUSB_DEVCTL); in musb_read_devctl()
462 * musb_set_host - set and initialize host mode
479 return -EINVAL; in musb_set_host()
488 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in musb_set_host()
494 dev_err(musb->controller, "%s: could not set host: %02x\n", in musb_set_host()
504 musb->is_active = 1; in musb_set_host()
513 * musb_set_peripheral - set and initialize peripheral mode
526 return -EINVAL; in musb_set_peripheral()
535 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in musb_set_peripheral()
541 dev_err(musb->controller, "%s: could not set peripheral: %02x\n", in musb_set_peripheral()
551 musb->is_active = 0; in musb_set_peripheral()
559 /*-------------------------------------------------------------------------*/
583 void __iomem *regs = musb->endpoints[0].regs; in musb_load_testpacket()
585 musb_ep_select(musb->mregs, 0); in musb_load_testpacket()
586 musb_write_fifo(musb->control_ep, in musb_load_testpacket()
591 /*-------------------------------------------------------------------------*/
594 * Handles OTG hnp timeouts, such as b_ase0_brst
601 spin_lock_irqsave(&musb->lock, flags); in musb_otg_timer_func()
605 "HNP: b_wait_acon timeout; back to b_peripheral"); in musb_otg_timer_func()
608 musb->is_active = 0; in musb_otg_timer_func()
612 musb_dbg(musb, "HNP: %s timeout", in musb_otg_timer_func()
618 musb_dbg(musb, "HNP: Unhandled mode %s", in musb_otg_timer_func()
621 spin_unlock_irqrestore(&musb->lock, flags); in musb_otg_timer_func()
625 * Stops the HNP transition. Caller must take care of locking.
629 struct usb_hcd *hcd = musb->hcd; in musb_hnp_stop()
630 void __iomem *mbase = musb->mregs; in musb_hnp_stop()
633 musb_dbg(musb, "HNP: stop from %s", musb_otg_state_string(musb)); in musb_hnp_stop()
638 musb_dbg(musb, "HNP: back to %s", musb_otg_state_string(musb)); in musb_hnp_stop()
641 musb_dbg(musb, "HNP: Disabling HR"); in musb_hnp_stop()
643 hcd->self.is_b_host = 0; in musb_hnp_stop()
652 musb_dbg(musb, "HNP: Stopping in unknown state %s", in musb_hnp_stop()
657 * When returning to A state after HNP, avoid hub_port_rebounce(), in musb_hnp_stop()
661 musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); in musb_hnp_stop()
674 musb->port1_status |= in musb_handle_intr_resume()
677 musb->rh_timer = jiffies in musb_handle_intr_resume()
680 musb->is_active = 1; in musb_handle_intr_resume()
682 schedule_delayed_work(&musb->finish_resume_work, in musb_handle_intr_resume()
687 musb->is_active = 1; in musb_handle_intr_resume()
710 musb->int_usb |= MUSB_INTR_DISCONNECT; in musb_handle_intr_resume()
711 musb->int_usb &= ~MUSB_INTR_SUSPEND; in musb_handle_intr_resume()
717 musb->int_usb &= ~MUSB_INTR_SUSPEND; in musb_handle_intr_resume()
730 void __iomem *mbase = musb->mregs; in musb_handle_intr_sessreq()
742 * - turn on VBUS (with silicon-specific mechanism) in musb_handle_intr_sessreq()
743 * - go through A_WAIT_VRISE in musb_handle_intr_sessreq()
744 * - ... to A_WAIT_BCON. in musb_handle_intr_sessreq()
748 musb->ep0_stage = MUSB_EP0_START; in musb_handle_intr_sessreq()
760 /* During connection as an A-Device, we may see a short in musb_handle_intr_vbuserr()
763 * (So: less common with truly self-powered devices, where in musb_handle_intr_vbuserr()
771 * (b) software: ignore non-repeated VBUS errors. in musb_handle_intr_vbuserr()
786 if (musb->vbuserr_retry) { in musb_handle_intr_vbuserr()
787 void __iomem *mbase = musb->mregs; in musb_handle_intr_vbuserr()
789 musb->vbuserr_retry--; in musb_handle_intr_vbuserr()
794 musb->port1_status |= in musb_handle_intr_vbuserr()
803 dev_printk(ignore ? KERN_DEBUG : KERN_ERR, musb->controller, in musb_handle_intr_vbuserr()
819 VBUSERR_RETRY_COUNT - musb->vbuserr_retry, in musb_handle_intr_vbuserr()
820 musb->port1_status); in musb_handle_intr_vbuserr()
835 * this silicon doesn't report ID-no-longer-grounded. in musb_handle_intr_suspend()
845 + msecs_to_jiffies(musb->a_wait_bcon in musb_handle_intr_suspend()
850 if (!musb->is_active) in musb_handle_intr_suspend()
855 musb->is_active = musb->g.b_hnp_enable; in musb_handle_intr_suspend()
856 if (musb->is_active) { in musb_handle_intr_suspend()
858 musb_dbg(musb, "HNP: Setting timer for b_ase0_brst"); in musb_handle_intr_suspend()
859 mod_timer(&musb->otg_timer, jiffies in musb_handle_intr_suspend()
865 if (musb->a_wait_bcon != 0) in musb_handle_intr_suspend()
867 + msecs_to_jiffies(musb->a_wait_bcon)); in musb_handle_intr_suspend()
871 musb->is_active = musb->hcd->self.b_hnp_enable; in musb_handle_intr_suspend()
879 musb->is_active = 0; in musb_handle_intr_suspend()
886 struct usb_hcd *hcd = musb->hcd; in musb_handle_intr_connect()
888 musb->is_active = 1; in musb_handle_intr_connect()
889 musb->ep0_stage = MUSB_EP0_START; in musb_handle_intr_connect()
891 musb->intrtxe = musb->epmask; in musb_handle_intr_connect()
892 musb_writew(musb->mregs, MUSB_INTRTXE, musb->intrtxe); in musb_handle_intr_connect()
893 musb->intrrxe = musb->epmask & 0xfffe; in musb_handle_intr_connect()
894 musb_writew(musb->mregs, MUSB_INTRRXE, musb->intrrxe); in musb_handle_intr_connect()
895 musb_writeb(musb->mregs, MUSB_INTRUSBE, 0xf7); in musb_handle_intr_connect()
896 musb->port1_status &= ~(USB_PORT_STAT_LOW_SPEED in musb_handle_intr_connect()
900 musb->port1_status |= USB_PORT_STAT_CONNECTION in musb_handle_intr_connect()
905 musb->port1_status |= USB_PORT_STAT_LOW_SPEED; in musb_handle_intr_connect()
911 musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host"); in musb_handle_intr_connect()
918 musb_dbg(musb, "HNP: CONNECT, now b_host"); in musb_handle_intr_connect()
921 if (musb->hcd) in musb_handle_intr_connect()
922 musb->hcd->self.is_b_host = 1; in musb_handle_intr_connect()
923 del_timer(&musb->otg_timer); in musb_handle_intr_connect()
930 hcd->self.is_b_host = 0; in musb_handle_intr_connect()
952 if (musb->a_wait_bcon != 0) in musb_handle_intr_disconnect()
954 + msecs_to_jiffies(musb->a_wait_bcon)); in musb_handle_intr_disconnect()
963 if (musb->hcd) in musb_handle_intr_disconnect()
964 musb->hcd->self.is_b_host = 0; in musb_handle_intr_disconnect()
1000 dev_err(musb->controller, "Babble\n"); in musb_handle_intr_reset()
1008 case OTG_STATE_A_WAIT_BCON: /* OPT TD.4.7-900ms */ in musb_handle_intr_reset()
1010 musb_dbg(musb, "HNP: in %s, %d msec timeout", in musb_handle_intr_reset()
1013 mod_timer(&musb->otg_timer, jiffies in musb_handle_intr_reset()
1017 del_timer(&musb->otg_timer); in musb_handle_intr_reset()
1021 musb_dbg(musb, "HNP: RESET (%s), to b_peripheral", in musb_handle_intr_reset()
1111 void __iomem *mbase = musb->mregs; in musb_stage0_irq()
1116 dev_dbg(musb->controller, "START_OF_FRAME\n"); in musb_stage0_irq()
1121 ep = musb->endpoints; in musb_stage0_irq()
1122 for (epnum = 1; (epnum < musb->nr_endpoints) in musb_stage0_irq()
1123 && (musb->epmask >= (1 << epnum)); in musb_stage0_irq()
1129 if (ep->dwWaitFrame >= frame) { in musb_stage0_irq()
1130 ep->dwWaitFrame = 0; in musb_stage0_irq()
1131 pr_debug("SOF --> periodic TX%s on %d\n", in musb_stage0_irq()
1132 ep->tx_channel ? " DMA" : "", in musb_stage0_irq()
1134 if (!ep->tx_channel) in musb_stage0_irq()
1143 schedule_delayed_work(&musb->irq_work, 0); in musb_stage0_irq()
1148 /*-------------------------------------------------------------------------*/
1152 void __iomem *mbase = musb->mregs; in musb_disable_interrupts()
1154 /* disable interrupts */ in musb_disable_interrupts()
1156 musb->intrtxe = 0; in musb_disable_interrupts()
1158 musb->intrrxe = 0; in musb_disable_interrupts()
1169 void __iomem *regs = musb->mregs; in musb_enable_interrupts()
1172 musb->intrtxe = musb->epmask; in musb_enable_interrupts()
1173 musb_writew(regs, MUSB_INTRTXE, musb->intrtxe); in musb_enable_interrupts()
1174 musb->intrrxe = musb->epmask & 0xfffe; in musb_enable_interrupts()
1175 musb_writew(regs, MUSB_INTRRXE, musb->intrrxe); in musb_enable_interrupts()
1185 void __iomem *regs = musb->mregs; in musb_start()
1197 * we will default to high-speed. in musb_start()
1199 if (musb->config->maximum_speed == USB_SPEED_HIGH || in musb_start()
1200 musb->config->maximum_speed == USB_SPEED_UNKNOWN) in musb_start()
1204 musb->is_active = 0; in musb_start()
1209 * (a) ID-grounded irq, host mode; in musb_start()
1213 if (musb->port_mode != MUSB_HOST && in musb_start()
1216 musb->is_active = 1; in musb_start()
1226 * Make the HDRC stop (disable interrupts, etc.);
1237 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); in musb_stop()
1240 * - mark host and/or peripheral drivers unusable/inactive in musb_stop()
1241 * - disable DMA (and enable it in HdrcStart) in musb_stop()
1242 * - make sure we can musb_start() after musb_stop(); with in musb_stop()
1244 * - ... in musb_stop()
1249 /*-------------------------------------------------------------------------*/
1252 * The silicon either has hard-wired endpoint configurations, or else
1255 * away from compile-time hardware parameters, we can no longer rely on
1272 /* mode 0 - fits in 2KB */
1281 /* mode 1 - fits in 4KB */
1290 /* mode 2 - fits in 4KB */
1300 /* mode 3 - fits in 4KB */
1310 /* mode 4 - fits in 16KB */
1341 /* mode 5 - fits in 8KB */
1373 * configure a fifo; for non-shared endpoints, this may be called
1382 void __iomem *mbase = musb->mregs; in fifo_setup()
1384 u16 maxpacket = cfg->maxpacket; in fifo_setup()
1388 /* expect hw_ep has already been zero-initialized */ in fifo_setup()
1390 size = ffs(max(maxpacket, (u16) 8)) - 1; in fifo_setup()
1393 c_size = size - 3; in fifo_setup()
1394 if (cfg->mode == BUF_DOUBLE) { in fifo_setup()
1396 (1 << (musb->config->ram_bits + 2))) in fifo_setup()
1397 return -EMSGSIZE; in fifo_setup()
1400 if ((offset + maxpacket) > (1 << (musb->config->ram_bits + 2))) in fifo_setup()
1401 return -EMSGSIZE; in fifo_setup()
1405 musb_writeb(mbase, MUSB_INDEX, hw_ep->epnum); in fifo_setup()
1410 if (hw_ep->epnum == 1) in fifo_setup()
1411 musb->bulk_ep = hw_ep; in fifo_setup()
1413 switch (cfg->style) { in fifo_setup()
1417 hw_ep->tx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); in fifo_setup()
1418 hw_ep->max_packet_sz_tx = maxpacket; in fifo_setup()
1423 hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); in fifo_setup()
1424 hw_ep->max_packet_sz_rx = maxpacket; in fifo_setup()
1429 hw_ep->rx_double_buffered = !!(c_size & MUSB_FIFOSZ_DPB); in fifo_setup()
1430 hw_ep->max_packet_sz_rx = maxpacket; in fifo_setup()
1434 hw_ep->tx_double_buffered = hw_ep->rx_double_buffered; in fifo_setup()
1435 hw_ep->max_packet_sz_tx = maxpacket; in fifo_setup()
1437 hw_ep->is_shared_fifo = true; in fifo_setup()
1444 musb->epmask |= (1 << hw_ep->epnum); in fifo_setup()
1458 struct musb_hw_ep *hw_ep = musb->endpoints; in ep_config_from_table()
1460 if (musb->config->fifo_cfg) { in ep_config_from_table()
1461 cfg = musb->config->fifo_cfg; in ep_config_from_table()
1462 n = musb->config->fifo_cfg_size; in ep_config_from_table()
1504 * be better than static musb->config->num_eps and DYN_FIFO_SIZE... in ep_config_from_table()
1508 u8 epn = cfg->hw_ep_num; in ep_config_from_table()
1510 if (epn >= musb->config->num_eps) { in ep_config_from_table()
1513 return -EINVAL; in ep_config_from_table()
1522 musb->nr_endpoints = max(epn, musb->nr_endpoints); in ep_config_from_table()
1527 n + 1, musb->config->num_eps * 2 - 1, in ep_config_from_table()
1528 offset, (1 << (musb->config->ram_bits + 2))); in ep_config_from_table()
1530 if (!musb->bulk_ep) { in ep_config_from_table()
1532 return -EINVAL; in ep_config_from_table()
1540 * ep_config_from_hw - when MUSB_C_DYNFIFO_DEF is false
1547 void __iomem *mbase = musb->mregs; in ep_config_from_hw()
1554 for (epnum = 1; epnum < musb->config->num_eps; epnum++) { in ep_config_from_hw()
1556 hw_ep = musb->endpoints + epnum; in ep_config_from_hw()
1562 /* FIXME set up hw_ep->{rx,tx}_double_buffered */ in ep_config_from_hw()
1565 if (hw_ep->max_packet_sz_tx < 512 in ep_config_from_hw()
1566 || hw_ep->max_packet_sz_rx < 512) in ep_config_from_hw()
1572 if (musb->bulk_ep) in ep_config_from_hw()
1574 musb->bulk_ep = hw_ep; in ep_config_from_hw()
1577 if (!musb->bulk_ep) { in ep_config_from_hw()
1579 return -EINVAL; in ep_config_from_hw()
1595 void __iomem *mbase = musb->mregs; in musb_core_init()
1602 strcpy(aInfo, (reg & MUSB_CONFIGDATA_UTMIDW) ? "UTMI-16" : "UTMI-8"); in musb_core_init()
1605 musb->dyn_fifo = true; in musb_core_init()
1609 musb->bulk_combine = true; in musb_core_init()
1613 musb->bulk_split = true; in musb_core_init()
1616 strcat(aInfo, ", HB-ISO Rx"); in musb_core_init()
1617 musb->hb_iso_rx = true; in musb_core_init()
1620 strcat(aInfo, ", HB-ISO Tx"); in musb_core_init()
1621 musb->hb_iso_tx = true; in musb_core_init()
1629 musb->is_multipoint = 1; in musb_core_init()
1632 musb->is_multipoint = 0; in musb_core_init()
1636 pr_err("%s: kernel must disable external hubs, please fix the configuration\n", in musb_core_init()
1642 musb->hwvers = musb_readw(mbase, MUSB_HWVERS); in musb_core_init()
1644 musb_driver_name, type, MUSB_HWVERS_MAJOR(musb->hwvers), in musb_core_init()
1645 MUSB_HWVERS_MINOR(musb->hwvers), in musb_core_init()
1646 (musb->hwvers & MUSB_HWVERS_RC) ? "RC" : ""); in musb_core_init()
1652 musb->nr_endpoints = 1; in musb_core_init()
1653 musb->epmask = 1; in musb_core_init()
1655 if (musb->dyn_fifo) in musb_core_init()
1664 for (i = 0; i < musb->nr_endpoints; i++) { in musb_core_init()
1665 struct musb_hw_ep *hw_ep = musb->endpoints + i; in musb_core_init()
1667 hw_ep->fifo = musb->io.fifo_offset(i) + mbase; in musb_core_init()
1669 if (musb->ops->quirks & MUSB_IN_TUSB) { in musb_core_init()
1670 hw_ep->fifo_async = musb->async + 0x400 + in musb_core_init()
1671 musb->io.fifo_offset(i); in musb_core_init()
1672 hw_ep->fifo_sync = musb->sync + 0x400 + in musb_core_init()
1673 musb->io.fifo_offset(i); in musb_core_init()
1674 hw_ep->fifo_sync_va = in musb_core_init()
1675 musb->sync_va + 0x400 + musb->io.fifo_offset(i); in musb_core_init()
1678 hw_ep->conf = mbase - 0x400 + TUSB_EP0_CONF; in musb_core_init()
1680 hw_ep->conf = mbase + 0x400 + in musb_core_init()
1681 (((i - 1) & 0xf) << 2); in musb_core_init()
1685 hw_ep->regs = musb->io.ep_offset(i, 0) + mbase; in musb_core_init()
1686 hw_ep->rx_reinit = 1; in musb_core_init()
1687 hw_ep->tx_reinit = 1; in musb_core_init()
1689 if (hw_ep->max_packet_sz_tx) { in musb_core_init()
1692 hw_ep->is_shared_fifo ? "shared" : "tx", in musb_core_init()
1693 hw_ep->tx_double_buffered in musb_core_init()
1695 hw_ep->max_packet_sz_tx); in musb_core_init()
1697 if (hw_ep->max_packet_sz_rx && !hw_ep->is_shared_fifo) { in musb_core_init()
1701 hw_ep->rx_double_buffered in musb_core_init()
1703 hw_ep->max_packet_sz_rx); in musb_core_init()
1705 if (!(hw_ep->max_packet_sz_tx || hw_ep->max_packet_sz_rx)) in musb_core_init()
1712 /*-------------------------------------------------------------------------*/
1716 * irq sources (phy, dma, etc) will be handled first, musb->int_* values
1728 if (!musb->int_usb && !musb->int_tx && !musb->int_rx) in musb_interrupt()
1731 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in musb_interrupt()
1755 if (musb->int_usb) in musb_interrupt()
1756 retval |= musb_stage0_irq(musb, musb->int_usb, devctl); in musb_interrupt()
1758 if (musb->int_tx & 1) { in musb_interrupt()
1765 musb->int_tx &= ~BIT(0); in musb_interrupt()
1768 status = musb->int_tx; in musb_interrupt()
1778 status = musb->int_rx; in musb_interrupt()
1797 MODULE_PARM_DESC(use_dma, "enable/disable use of DMA");
1836 * musb_mailbox - optional phy notifier function
1847 return -ENODEV; in musb_mailbox()
1851 /*-------------------------------------------------------------------------*/
1860 spin_lock_irqsave(&musb->lock, flags); in mode_show()
1862 spin_unlock_irqrestore(&musb->lock, flags); in mode_show()
1875 spin_lock_irqsave(&musb->lock, flags); in mode_store()
1883 status = -EINVAL; in mode_store()
1884 spin_unlock_irqrestore(&musb->lock, flags); in mode_store()
1900 return -EINVAL; in vbus_store()
1903 spin_lock_irqsave(&musb->lock, flags); in vbus_store()
1905 musb->a_wait_bcon = val ? max_t(int, val, OTG_TIME_A_WAIT_BCON) : 0 ; in vbus_store()
1907 musb->is_active = 0; in vbus_store()
1909 spin_unlock_irqrestore(&musb->lock, flags); in vbus_store()
1924 spin_lock_irqsave(&musb->lock, flags); in vbus_show()
1925 val = musb->a_wait_bcon; in vbus_show()
1929 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in vbus_show()
1936 spin_unlock_irqrestore(&musb->lock, flags); in vbus_show()
1956 return -EINVAL; in srp_store()
1986 if (musb->quirk_retries && !musb->flush_irq_work) { in musb_state_needs_recheck()
1988 schedule_delayed_work(&musb->irq_work, in musb_state_needs_recheck()
1990 musb->quirk_retries--; in musb_state_needs_recheck()
2004 * elsewhere, proper locking must be implemented for musb->session.
2011 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in musb_pm_runtime_check_session()
2030 if (!musb->session) in musb_pm_runtime_check_session()
2033 pm_runtime_mark_last_busy(musb->controller); in musb_pm_runtime_check_session()
2034 pm_runtime_put_autosuspend(musb->controller); in musb_pm_runtime_check_session()
2035 musb->session = false; in musb_pm_runtime_check_session()
2043 if (s == musb->session) in musb_pm_runtime_check_session()
2049 error = pm_runtime_get_sync(musb->controller); in musb_pm_runtime_check_session()
2051 dev_err(musb->controller, "Could not enable: %i\n", in musb_pm_runtime_check_session()
2053 musb->quirk_retries = 3; in musb_pm_runtime_check_session()
2056 * We can get a spurious MUSB_INTR_SESSREQ interrupt on start-up in musb_pm_runtime_check_session()
2057 * in B-peripheral mode with nothing connected and the session in musb_pm_runtime_check_session()
2061 schedule_delayed_work(&musb->irq_work, in musb_pm_runtime_check_session()
2065 pm_runtime_mark_last_busy(musb->controller); in musb_pm_runtime_check_session()
2066 pm_runtime_put_autosuspend(musb->controller); in musb_pm_runtime_check_session()
2069 musb->session = s; in musb_pm_runtime_check_session()
2078 error = pm_runtime_resume_and_get(musb->controller); in musb_irq_work()
2080 dev_err(musb->controller, "Could not enable: %i\n", error); in musb_irq_work()
2087 if (musb_get_state(musb) != musb->xceiv_old_state) { in musb_irq_work()
2088 musb->xceiv_old_state = musb_get_state(musb); in musb_irq_work()
2089 sysfs_notify(&musb->controller->kobj, NULL, "mode"); in musb_irq_work()
2092 pm_runtime_mark_last_busy(musb->controller); in musb_irq_work()
2093 pm_runtime_put_autosuspend(musb->controller); in musb_irq_work()
2116 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in musb_recover_from_babble()
2118 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in musb_recover_from_babble()
2127 if (musb->dyn_fifo) in musb_recover_from_babble()
2137 /* --------------------------------------------------------------------------
2153 INIT_LIST_HEAD(&musb->control); in allocate_instance()
2154 INIT_LIST_HEAD(&musb->in_bulk); in allocate_instance()
2155 INIT_LIST_HEAD(&musb->out_bulk); in allocate_instance()
2156 INIT_LIST_HEAD(&musb->pending_list); in allocate_instance()
2158 musb->vbuserr_retry = VBUSERR_RETRY_COUNT; in allocate_instance()
2159 musb->a_wait_bcon = OTG_TIME_A_WAIT_BCON; in allocate_instance()
2160 musb->mregs = mbase; in allocate_instance()
2161 musb->ctrl_base = mbase; in allocate_instance()
2162 musb->nIrq = -ENODEV; in allocate_instance()
2163 musb->config = config; in allocate_instance()
2164 BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS); in allocate_instance()
2165 for (epnum = 0, ep = musb->endpoints; in allocate_instance()
2166 epnum < musb->config->num_eps; in allocate_instance()
2168 ep->musb = musb; in allocate_instance()
2169 ep->epnum = epnum; in allocate_instance()
2172 musb->controller = dev; in allocate_instance()
2190 * cleanup after everything's been de-activated. in musb_free()
2193 if (musb->nIrq >= 0) { in musb_free()
2194 if (musb->irq_wake) in musb_free()
2195 disable_irq_wake(musb->nIrq); in musb_free()
2196 free_irq(musb->nIrq, musb); in musb_free()
2211 * musb_queue_resume_work(). Callers must take musb->lock.
2219 spin_lock_irqsave(&musb->list_lock, flags); in musb_run_resume_work()
2220 list_for_each_entry_safe(w, _w, &musb->pending_list, node) { in musb_run_resume_work()
2221 if (w->callback) { in musb_run_resume_work()
2222 error = w->callback(musb, w->data); in musb_run_resume_work()
2224 dev_err(musb->controller, in musb_run_resume_work()
2226 w->callback, error); in musb_run_resume_work()
2229 list_del(&w->node); in musb_run_resume_work()
2230 devm_kfree(musb->controller, w); in musb_run_resume_work()
2232 spin_unlock_irqrestore(&musb->list_lock, flags); in musb_run_resume_work()
2240 * on resume. Caller must take musb->lock and must hold an RPM reference.
2243 * resume is done calling musb_run_resume_work() and return -EINPROGRESS
2256 return -EINVAL; in musb_queue_resume_work()
2258 spin_lock_irqsave(&musb->list_lock, flags); in musb_queue_resume_work()
2259 is_suspended = musb->is_runtime_suspended; in musb_queue_resume_work()
2262 w = devm_kzalloc(musb->controller, sizeof(*w), GFP_ATOMIC); in musb_queue_resume_work()
2264 error = -ENOMEM; in musb_queue_resume_work()
2268 w->callback = callback; in musb_queue_resume_work()
2269 w->data = data; in musb_queue_resume_work()
2271 list_add_tail(&w->node, &musb->pending_list); in musb_queue_resume_work()
2276 spin_unlock_irqrestore(&musb->list_lock, flags); in musb_queue_resume_work()
2292 spin_lock_irqsave(&musb->lock, flags); in musb_deassert_reset()
2294 if (musb->port1_status & USB_PORT_STAT_RESET) in musb_deassert_reset()
2297 spin_unlock_irqrestore(&musb->lock, flags); in musb_deassert_reset()
2301 * Perform generic per-controller initialization.
2306 * not yet corrected for platform-specific offsets
2320 status = -ENODEV; in musb_init_controller()
2325 musb = allocate_instance(dev, plat->config, ctrl); in musb_init_controller()
2327 status = -ENOMEM; in musb_init_controller()
2331 spin_lock_init(&musb->lock); in musb_init_controller()
2332 spin_lock_init(&musb->list_lock); in musb_init_controller()
2333 musb->min_power = plat->min_power; in musb_init_controller()
2334 musb->ops = plat->platform_ops; in musb_init_controller()
2335 musb->port_mode = plat->mode; in musb_init_controller()
2348 * - adjusts musb->mregs in musb_init_controller()
2349 * - sets the musb->isr in musb_init_controller()
2350 * - may initialize an integrated transceiver in musb_init_controller()
2351 * - initializes musb->xceiv, usually by otg_get_phy() in musb_init_controller()
2352 * - stops powering VBUS in musb_init_controller()
2357 * isp1504, non-OTG, etc) mostly hooking up through ULPI. in musb_init_controller()
2363 if (!musb->isr) { in musb_init_controller()
2364 status = -ENODEV; in musb_init_controller()
2370 if (musb->ops->quirks & MUSB_INDEXED_EP) { in musb_init_controller()
2371 musb->io.ep_offset = musb_indexed_ep_offset; in musb_init_controller()
2372 musb->io.ep_select = musb_indexed_ep_select; in musb_init_controller()
2374 musb->io.ep_offset = musb_flat_ep_offset; in musb_init_controller()
2375 musb->io.ep_select = musb_flat_ep_select; in musb_init_controller()
2378 if (musb->ops->quirks & MUSB_G_NO_SKB_RESERVE) in musb_init_controller()
2379 musb->g.quirk_avoids_skb_reserve = 1; in musb_init_controller()
2382 if (musb->ops->ep_offset) in musb_init_controller()
2383 musb->io.ep_offset = musb->ops->ep_offset; in musb_init_controller()
2384 if (musb->ops->ep_select) in musb_init_controller()
2385 musb->io.ep_select = musb->ops->ep_select; in musb_init_controller()
2387 if (musb->ops->fifo_mode) in musb_init_controller()
2388 fifo_mode = musb->ops->fifo_mode; in musb_init_controller()
2392 if (musb->ops->fifo_offset) in musb_init_controller()
2393 musb->io.fifo_offset = musb->ops->fifo_offset; in musb_init_controller()
2395 musb->io.fifo_offset = musb_default_fifo_offset; in musb_init_controller()
2397 if (musb->ops->busctl_offset) in musb_init_controller()
2398 musb->io.busctl_offset = musb->ops->busctl_offset; in musb_init_controller()
2400 musb->io.busctl_offset = musb_default_busctl_offset; in musb_init_controller()
2402 if (musb->ops->readb) in musb_init_controller()
2403 musb_readb = musb->ops->readb; in musb_init_controller()
2404 if (musb->ops->writeb) in musb_init_controller()
2405 musb_writeb = musb->ops->writeb; in musb_init_controller()
2406 if (musb->ops->clearb) in musb_init_controller()
2407 musb_clearb = musb->ops->clearb; in musb_init_controller()
2411 if (musb->ops->readw) in musb_init_controller()
2412 musb_readw = musb->ops->readw; in musb_init_controller()
2413 if (musb->ops->writew) in musb_init_controller()
2414 musb_writew = musb->ops->writew; in musb_init_controller()
2415 if (musb->ops->clearw) in musb_init_controller()
2416 musb_clearw = musb->ops->clearw; in musb_init_controller()
2421 if (!musb->ops->dma_init || !musb->ops->dma_exit) { in musb_init_controller()
2423 status = -ENODEV; in musb_init_controller()
2426 musb_dma_controller_create = musb->ops->dma_init; in musb_init_controller()
2427 musb_dma_controller_destroy = musb->ops->dma_exit; in musb_init_controller()
2430 if (musb->ops->read_fifo) in musb_init_controller()
2431 musb->io.read_fifo = musb->ops->read_fifo; in musb_init_controller()
2433 musb->io.read_fifo = musb_default_read_fifo; in musb_init_controller()
2435 if (musb->ops->write_fifo) in musb_init_controller()
2436 musb->io.write_fifo = musb->ops->write_fifo; in musb_init_controller()
2438 musb->io.write_fifo = musb_default_write_fifo; in musb_init_controller()
2440 if (musb->ops->get_toggle) in musb_init_controller()
2441 musb->io.get_toggle = musb->ops->get_toggle; in musb_init_controller()
2443 musb->io.get_toggle = musb_default_get_toggle; in musb_init_controller()
2445 if (musb->ops->set_toggle) in musb_init_controller()
2446 musb->io.set_toggle = musb->ops->set_toggle; in musb_init_controller()
2448 musb->io.set_toggle = musb_default_set_toggle; in musb_init_controller()
2450 if (IS_ENABLED(CONFIG_USB_PHY) && musb->xceiv && !musb->xceiv->io_ops) { in musb_init_controller()
2451 musb->xceiv->io_dev = musb->controller; in musb_init_controller()
2452 musb->xceiv->io_priv = musb->mregs; in musb_init_controller()
2453 musb->xceiv->io_ops = &musb_ulpi_access; in musb_init_controller()
2456 if (musb->ops->phy_callback) in musb_init_controller()
2457 musb_phy_callback = musb->ops->phy_callback; in musb_init_controller()
2466 pm_runtime_use_autosuspend(musb->controller); in musb_init_controller()
2467 pm_runtime_set_autosuspend_delay(musb->controller, 500); in musb_init_controller()
2468 pm_runtime_enable(musb->controller); in musb_init_controller()
2469 pm_runtime_get_sync(musb->controller); in musb_init_controller()
2471 status = usb_phy_init(musb->xceiv); in musb_init_controller()
2475 if (use_dma && dev->dma_mask) { in musb_init_controller()
2476 musb->dma_controller = in musb_init_controller()
2477 musb_dma_controller_create(musb, musb->mregs); in musb_init_controller()
2478 if (IS_ERR(musb->dma_controller)) { in musb_init_controller()
2479 status = PTR_ERR(musb->dma_controller); in musb_init_controller()
2487 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); in musb_init_controller()
2490 musb_writeb(musb->mregs, MUSB_POWER, 0); in musb_init_controller()
2493 INIT_DELAYED_WORK(&musb->irq_work, musb_irq_work); in musb_init_controller()
2494 INIT_DELAYED_WORK(&musb->deassert_reset_work, musb_deassert_reset); in musb_init_controller()
2495 INIT_DELAYED_WORK(&musb->finish_resume_work, musb_host_finish_resume); in musb_init_controller()
2498 status = musb_core_init(plat->config->multipoint in musb_init_controller()
2504 timer_setup(&musb->otg_timer, musb_otg_timer_func, 0); in musb_init_controller()
2507 if (request_irq(nIrq, musb->isr, IRQF_SHARED, dev_name(dev), musb)) { in musb_init_controller()
2509 status = -ENODEV; in musb_init_controller()
2512 musb->nIrq = nIrq; in musb_init_controller()
2515 musb->irq_wake = 1; in musb_init_controller()
2518 musb->irq_wake = 0; in musb_init_controller()
2522 if (plat->extvbus) { in musb_init_controller()
2523 u8 busctl = musb_readb(musb->mregs, MUSB_ULPI_BUSCONTROL); in musb_init_controller()
2525 musb_writeb(musb->mregs, MUSB_ULPI_BUSCONTROL, busctl); in musb_init_controller()
2531 switch (musb->port_mode) { in musb_init_controller()
2533 status = musb_host_setup(musb, plat->power); in musb_init_controller()
2545 status = musb_host_setup(musb, plat->power); in musb_init_controller()
2556 dev_err(dev, "unsupported port mode %d\n", musb->port_mode); in musb_init_controller()
2565 musb->is_initialized = 1; in musb_init_controller()
2566 pm_runtime_mark_last_busy(musb->controller); in musb_init_controller()
2567 pm_runtime_put_autosuspend(musb->controller); in musb_init_controller()
2572 cancel_delayed_work_sync(&musb->irq_work); in musb_init_controller()
2573 cancel_delayed_work_sync(&musb->finish_resume_work); in musb_init_controller()
2574 cancel_delayed_work_sync(&musb->deassert_reset_work); in musb_init_controller()
2575 if (musb->dma_controller) in musb_init_controller()
2576 musb_dma_controller_destroy(musb->dma_controller); in musb_init_controller()
2579 usb_phy_shutdown(musb->xceiv); in musb_init_controller()
2582 pm_runtime_dont_use_autosuspend(musb->controller); in musb_init_controller()
2583 pm_runtime_put_sync(musb->controller); in musb_init_controller()
2584 pm_runtime_disable(musb->controller); in musb_init_controller()
2587 if (musb->irq_wake) in musb_init_controller()
2592 dev_err_probe(musb->controller, status, "%s failed\n", __func__); in musb_init_controller()
2602 /*-------------------------------------------------------------------------*/
2609 struct device *dev = &pdev->dev; in musb_probe()
2625 struct device *dev = &pdev->dev; in musb_remove()
2630 * - Host mode: host may still be active in musb_remove()
2631 * - Peripheral mode: peripheral is deactivated (or never-activated) in musb_remove()
2632 * - OTG mode: both roles are deactivated (or never-activated) in musb_remove()
2636 cancel_delayed_work_sync(&musb->irq_work); in musb_remove()
2637 cancel_delayed_work_sync(&musb->finish_resume_work); in musb_remove()
2638 cancel_delayed_work_sync(&musb->deassert_reset_work); in musb_remove()
2639 pm_runtime_get_sync(musb->controller); in musb_remove()
2644 spin_lock_irqsave(&musb->lock, flags); in musb_remove()
2646 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); in musb_remove()
2647 spin_unlock_irqrestore(&musb->lock, flags); in musb_remove()
2650 pm_runtime_dont_use_autosuspend(musb->controller); in musb_remove()
2651 pm_runtime_put_sync(musb->controller); in musb_remove()
2652 pm_runtime_disable(musb->controller); in musb_remove()
2654 if (musb->dma_controller) in musb_remove()
2655 musb_dma_controller_destroy(musb->dma_controller); in musb_remove()
2656 usb_phy_shutdown(musb->xceiv); in musb_remove()
2666 void __iomem *musb_base = musb->mregs; in musb_save_context()
2669 musb->context.frame = musb_readw(musb_base, MUSB_FRAME); in musb_save_context()
2670 musb->context.testmode = musb_readb(musb_base, MUSB_TESTMODE); in musb_save_context()
2671 musb->context.busctl = musb_readb(musb_base, MUSB_ULPI_BUSCONTROL); in musb_save_context()
2672 musb->context.power = musb_readb(musb_base, MUSB_POWER); in musb_save_context()
2673 musb->context.intrusbe = musb_readb(musb_base, MUSB_INTRUSBE); in musb_save_context()
2674 musb->context.index = musb_readb(musb_base, MUSB_INDEX); in musb_save_context()
2675 musb->context.devctl = musb_readb(musb_base, MUSB_DEVCTL); in musb_save_context()
2677 for (i = 0; i < musb->config->num_eps; ++i) { in musb_save_context()
2678 epio = musb->endpoints[i].regs; in musb_save_context()
2683 musb->context.index_regs[i].txmaxp = in musb_save_context()
2685 musb->context.index_regs[i].txcsr = in musb_save_context()
2687 musb->context.index_regs[i].rxmaxp = in musb_save_context()
2689 musb->context.index_regs[i].rxcsr = in musb_save_context()
2692 if (musb->dyn_fifo) { in musb_save_context()
2693 musb->context.index_regs[i].txfifoadd = in musb_save_context()
2695 musb->context.index_regs[i].rxfifoadd = in musb_save_context()
2697 musb->context.index_regs[i].txfifosz = in musb_save_context()
2699 musb->context.index_regs[i].rxfifosz = in musb_save_context()
2703 musb->context.index_regs[i].txtype = in musb_save_context()
2705 musb->context.index_regs[i].txinterval = in musb_save_context()
2707 musb->context.index_regs[i].rxtype = in musb_save_context()
2709 musb->context.index_regs[i].rxinterval = in musb_save_context()
2712 musb->context.index_regs[i].txfunaddr = in musb_save_context()
2714 musb->context.index_regs[i].txhubaddr = in musb_save_context()
2716 musb->context.index_regs[i].txhubport = in musb_save_context()
2719 musb->context.index_regs[i].rxfunaddr = in musb_save_context()
2721 musb->context.index_regs[i].rxhubaddr = in musb_save_context()
2723 musb->context.index_regs[i].rxhubport = in musb_save_context()
2731 void __iomem *musb_base = musb->mregs; in musb_restore_context()
2735 musb_writew(musb_base, MUSB_FRAME, musb->context.frame); in musb_restore_context()
2736 musb_writeb(musb_base, MUSB_TESTMODE, musb->context.testmode); in musb_restore_context()
2737 musb_writeb(musb_base, MUSB_ULPI_BUSCONTROL, musb->context.busctl); in musb_restore_context()
2742 musb->context.power &= ~(MUSB_POWER_SUSPENDM | MUSB_POWER_RESUME); in musb_restore_context()
2743 power |= musb->context.power; in musb_restore_context()
2746 musb_writew(musb_base, MUSB_INTRTXE, musb->intrtxe); in musb_restore_context()
2747 musb_writew(musb_base, MUSB_INTRRXE, musb->intrrxe); in musb_restore_context()
2748 musb_writeb(musb_base, MUSB_INTRUSBE, musb->context.intrusbe); in musb_restore_context()
2749 if (musb->context.devctl & MUSB_DEVCTL_SESSION) in musb_restore_context()
2750 musb_writeb(musb_base, MUSB_DEVCTL, musb->context.devctl); in musb_restore_context()
2752 for (i = 0; i < musb->config->num_eps; ++i) { in musb_restore_context()
2753 epio = musb->endpoints[i].regs; in musb_restore_context()
2759 musb->context.index_regs[i].txmaxp); in musb_restore_context()
2761 musb->context.index_regs[i].txcsr); in musb_restore_context()
2763 musb->context.index_regs[i].rxmaxp); in musb_restore_context()
2765 musb->context.index_regs[i].rxcsr); in musb_restore_context()
2767 if (musb->dyn_fifo) { in musb_restore_context()
2769 musb->context.index_regs[i].txfifosz); in musb_restore_context()
2771 musb->context.index_regs[i].rxfifosz); in musb_restore_context()
2773 musb->context.index_regs[i].txfifoadd); in musb_restore_context()
2775 musb->context.index_regs[i].rxfifoadd); in musb_restore_context()
2779 musb->context.index_regs[i].txtype); in musb_restore_context()
2781 musb->context.index_regs[i].txinterval); in musb_restore_context()
2783 musb->context.index_regs[i].rxtype); in musb_restore_context()
2786 musb->context.index_regs[i].rxinterval); in musb_restore_context()
2788 musb->context.index_regs[i].txfunaddr); in musb_restore_context()
2790 musb->context.index_regs[i].txhubaddr); in musb_restore_context()
2792 musb->context.index_regs[i].txhubport); in musb_restore_context()
2795 musb->context.index_regs[i].rxfunaddr); in musb_restore_context()
2797 musb->context.index_regs[i].rxhubaddr); in musb_restore_context()
2799 musb->context.index_regs[i].rxhubport); in musb_restore_context()
2801 musb_writeb(musb_base, MUSB_INDEX, musb->context.index); in musb_restore_context()
2819 musb->flush_irq_work = true; in musb_suspend()
2820 while (flush_delayed_work(&musb->irq_work)) in musb_suspend()
2822 musb->flush_irq_work = false; in musb_suspend()
2824 if (!(musb->ops->quirks & MUSB_PRESERVE_SESSION)) in musb_suspend()
2825 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); in musb_suspend()
2827 WARN_ON(!list_empty(&musb->pending_list)); in musb_suspend()
2829 spin_lock_irqsave(&musb->lock, flags); in musb_suspend()
2837 * they will even be wakeup-enabled. in musb_suspend()
2843 spin_unlock_irqrestore(&musb->lock, flags); in musb_suspend()
2867 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in musb_resume()
2869 if ((devctl & mask) != (musb->context.devctl & mask)) in musb_resume()
2870 musb->port1_status = 0; in musb_resume()
2876 if (musb->port_mode == MUSB_HOST && in musb_resume()
2877 !(musb->ops->quirks & MUSB_PRESERVE_SESSION)) { in musb_resume()
2879 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in musb_resume()
2882 spin_lock_irqsave(&musb->lock, flags); in musb_resume()
2885 dev_err(musb->controller, "resume work failed with %i\n", in musb_resume()
2887 spin_unlock_irqrestore(&musb->lock, flags); in musb_resume()
2900 musb->is_runtime_suspended = 1; in musb_runtime_suspend()
2920 if (!musb->is_initialized) in musb_runtime_resume()
2925 spin_lock_irqsave(&musb->lock, flags); in musb_runtime_resume()
2928 dev_err(musb->controller, "resume work failed with %i\n", in musb_runtime_resume()
2930 musb->is_runtime_suspended = 0; in musb_runtime_resume()
2931 spin_unlock_irqrestore(&musb->lock, flags); in musb_runtime_resume()