Lines Matching +full:jz4740 +full:- +full:musb
1 // SPDX-License-Identifier: GPL-2.0
3 * MUSB OTG driver core code
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 /*-------------------------------------------------------------------------*/
105 static inline struct musb *dev_to_musb(struct device *dev) in dev_to_musb()
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() local
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() local
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()
436 (*musb_dma_controller_create)(struct musb *musb, void __iomem *base);
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()
456 static u8 musb_read_devctl(struct musb *musb) in musb_read_devctl() argument
458 return musb_readb(musb->mregs, MUSB_DEVCTL); in musb_read_devctl()
462 * musb_set_host - set and initialize host mode
463 * @musb: musb controller driver data
465 * At least some musb revisions need to enable devctl session bit in
470 * Note that the SoC glue code may need to wait for musb to settle
473 int musb_set_host(struct musb *musb) in musb_set_host() argument
478 if (!musb) in musb_set_host()
479 return -EINVAL; in musb_set_host()
481 devctl = musb_read_devctl(musb); in musb_set_host()
483 trace_musb_state(musb, devctl, "Already in host mode"); in musb_set_host()
488 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in musb_set_host()
490 error = readx_poll_timeout(musb_read_devctl, musb, devctl, in musb_set_host()
494 dev_err(musb->controller, "%s: could not set host: %02x\n", in musb_set_host()
500 devctl = musb_read_devctl(musb); in musb_set_host()
501 trace_musb_state(musb, devctl, "Host mode set"); in musb_set_host()
504 musb->is_active = 1; in musb_set_host()
505 musb_set_state(musb, OTG_STATE_A_IDLE); in musb_set_host()
506 MUSB_HST_MODE(musb); in musb_set_host()
513 * musb_set_peripheral - set and initialize peripheral mode
514 * @musb: musb controller driver data
520 int musb_set_peripheral(struct musb *musb) in musb_set_peripheral() argument
525 if (!musb) in musb_set_peripheral()
526 return -EINVAL; in musb_set_peripheral()
528 devctl = musb_read_devctl(musb); in musb_set_peripheral()
530 trace_musb_state(musb, devctl, "Already in peripheral mode"); in musb_set_peripheral()
535 musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); in musb_set_peripheral()
537 error = readx_poll_timeout(musb_read_devctl, musb, devctl, in musb_set_peripheral()
541 dev_err(musb->controller, "%s: could not set peripheral: %02x\n", in musb_set_peripheral()
547 devctl = musb_read_devctl(musb); in musb_set_peripheral()
548 trace_musb_state(musb, devctl, "Peripheral mode set"); in musb_set_peripheral()
551 musb->is_active = 0; in musb_set_peripheral()
552 musb_set_state(musb, OTG_STATE_B_IDLE); in musb_set_peripheral()
553 MUSB_DEV_MODE(musb); in musb_set_peripheral()
559 /*-------------------------------------------------------------------------*/
581 void musb_load_testpacket(struct musb *musb) in musb_load_testpacket() argument
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 /*-------------------------------------------------------------------------*/
598 struct musb *musb = from_timer(musb, t, otg_timer); in musb_otg_timer_func() local
601 spin_lock_irqsave(&musb->lock, flags); in musb_otg_timer_func()
602 switch (musb_get_state(musb)) { in musb_otg_timer_func()
604 musb_dbg(musb, in musb_otg_timer_func()
606 musb_g_disconnect(musb); in musb_otg_timer_func()
607 musb_set_state(musb, OTG_STATE_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()
613 musb_otg_state_string(musb)); in musb_otg_timer_func()
614 musb_platform_set_vbus(musb, 0); in musb_otg_timer_func()
615 musb_set_state(musb, OTG_STATE_A_WAIT_VFALL); in musb_otg_timer_func()
618 musb_dbg(musb, "HNP: Unhandled mode %s", in musb_otg_timer_func()
619 musb_otg_state_string(musb)); in musb_otg_timer_func()
621 spin_unlock_irqrestore(&musb->lock, flags); in musb_otg_timer_func()
627 void musb_hnp_stop(struct musb *musb) in musb_hnp_stop() argument
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()
635 switch (musb_get_state(musb)) { in musb_hnp_stop()
637 musb_g_disconnect(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()
644 musb_set_state(musb, OTG_STATE_B_PERIPHERAL); in musb_hnp_stop()
645 MUSB_DEV_MODE(musb); in musb_hnp_stop()
652 musb_dbg(musb, "HNP: Stopping in unknown state %s", in musb_hnp_stop()
653 musb_otg_state_string(musb)); in musb_hnp_stop()
661 musb->port1_status &= ~(USB_PORT_STAT_C_CONNECTION << 16); in musb_hnp_stop()
664 static void musb_recover_from_babble(struct musb *musb);
666 static void musb_handle_intr_resume(struct musb *musb, u8 devctl) in musb_handle_intr_resume() argument
668 musb_dbg(musb, "RESUME (%s)", musb_otg_state_string(musb)); in musb_handle_intr_resume()
671 switch (musb_get_state(musb)) { in musb_handle_intr_resume()
674 musb->port1_status |= in musb_handle_intr_resume()
677 musb->rh_timer = jiffies in musb_handle_intr_resume()
679 musb_set_state(musb, OTG_STATE_A_HOST); in musb_handle_intr_resume()
680 musb->is_active = 1; in musb_handle_intr_resume()
681 musb_host_resume_root_hub(musb); in musb_handle_intr_resume()
682 schedule_delayed_work(&musb->finish_resume_work, in musb_handle_intr_resume()
686 musb_set_state(musb, OTG_STATE_B_PERIPHERAL); in musb_handle_intr_resume()
687 musb->is_active = 1; in musb_handle_intr_resume()
688 MUSB_DEV_MODE(musb); in musb_handle_intr_resume()
693 musb_otg_state_string(musb)); in musb_handle_intr_resume()
696 switch (musb_get_state(musb)) { in musb_handle_intr_resume()
699 musb_set_state(musb, OTG_STATE_A_HOST); in musb_handle_intr_resume()
700 musb_host_resume_root_hub(musb); 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()
714 musb_g_resume(musb); in musb_handle_intr_resume()
717 musb->int_usb &= ~MUSB_INTR_SUSPEND; in musb_handle_intr_resume()
722 musb_otg_state_string(musb)); in musb_handle_intr_resume()
728 static irqreturn_t musb_handle_intr_sessreq(struct musb *musb, u8 devctl) in musb_handle_intr_sessreq() argument
730 void __iomem *mbase = musb->mregs; in musb_handle_intr_sessreq()
734 musb_dbg(musb, "SessReq while on B state"); in musb_handle_intr_sessreq()
738 musb_dbg(musb, "SESSION_REQUEST (%s)", musb_otg_state_string(musb)); 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()
749 musb_set_state(musb, OTG_STATE_A_IDLE); in musb_handle_intr_sessreq()
750 MUSB_HST_MODE(musb); in musb_handle_intr_sessreq()
751 musb_platform_set_vbus(musb, 1); in musb_handle_intr_sessreq()
756 static void musb_handle_intr_vbuserr(struct musb *musb, u8 devctl) in musb_handle_intr_vbuserr() argument
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()
776 switch (musb_get_state(musb)) { 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()
805 musb_otg_state_string(musb), 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()
824 musb_platform_set_vbus(musb, 0); in musb_handle_intr_vbuserr()
827 static void musb_handle_intr_suspend(struct musb *musb, u8 devctl) in musb_handle_intr_suspend() argument
829 musb_dbg(musb, "SUSPEND (%s) devctl %02x", in musb_handle_intr_suspend()
830 musb_otg_state_string(musb), devctl); in musb_handle_intr_suspend()
832 switch (musb_get_state(musb)) { in musb_handle_intr_suspend()
835 * this silicon doesn't report ID-no-longer-grounded. in musb_handle_intr_suspend()
841 musb_hnp_stop(musb); in musb_handle_intr_suspend()
842 musb_host_resume_root_hub(musb); in musb_handle_intr_suspend()
843 musb_root_disconnect(musb); in musb_handle_intr_suspend()
844 musb_platform_try_idle(musb, jiffies 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()
854 musb_g_suspend(musb); 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()
857 musb_set_state(musb, OTG_STATE_B_WAIT_ACON); 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()
866 musb_platform_try_idle(musb, jiffies in musb_handle_intr_suspend()
867 + msecs_to_jiffies(musb->a_wait_bcon)); in musb_handle_intr_suspend()
870 musb_set_state(musb, OTG_STATE_A_SUSPEND); in musb_handle_intr_suspend()
871 musb->is_active = musb->hcd->self.b_hnp_enable; in musb_handle_intr_suspend()
875 musb_dbg(musb, "REVISIT: SUSPEND as B_HOST"); in musb_handle_intr_suspend()
879 musb->is_active = 0; in musb_handle_intr_suspend()
884 static void musb_handle_intr_connect(struct musb *musb, u8 devctl, u8 int_usb) in musb_handle_intr_connect() argument
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()
908 switch (musb_get_state(musb)) { in musb_handle_intr_connect()
911 musb_dbg(musb, "HNP: SUSPEND+CONNECT, now b_host"); in musb_handle_intr_connect()
915 musb_dbg(musb, "CONNECT as b_peripheral???"); in musb_handle_intr_connect()
918 musb_dbg(musb, "HNP: CONNECT, now b_host"); in musb_handle_intr_connect()
920 musb_set_state(musb, OTG_STATE_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()
928 musb_set_state(musb, OTG_STATE_A_HOST); in musb_handle_intr_connect()
930 hcd->self.is_b_host = 0; in musb_handle_intr_connect()
935 musb_host_poke_root_hub(musb); in musb_handle_intr_connect()
937 musb_dbg(musb, "CONNECT (%s) devctl %02x", in musb_handle_intr_connect()
938 musb_otg_state_string(musb), devctl); in musb_handle_intr_connect()
941 static void musb_handle_intr_disconnect(struct musb *musb, u8 devctl) in musb_handle_intr_disconnect() argument
943 musb_dbg(musb, "DISCONNECT (%s) as %s, devctl %02x", in musb_handle_intr_disconnect()
944 musb_otg_state_string(musb), in musb_handle_intr_disconnect()
945 MUSB_MODE(musb), devctl); in musb_handle_intr_disconnect()
947 switch (musb_get_state(musb)) { in musb_handle_intr_disconnect()
950 musb_host_resume_root_hub(musb); in musb_handle_intr_disconnect()
951 musb_root_disconnect(musb); in musb_handle_intr_disconnect()
952 if (musb->a_wait_bcon != 0) in musb_handle_intr_disconnect()
953 musb_platform_try_idle(musb, jiffies in musb_handle_intr_disconnect()
954 + msecs_to_jiffies(musb->a_wait_bcon)); in musb_handle_intr_disconnect()
962 musb_root_disconnect(musb); 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()
965 musb_set_state(musb, OTG_STATE_B_PERIPHERAL); in musb_handle_intr_disconnect()
966 MUSB_DEV_MODE(musb); in musb_handle_intr_disconnect()
967 musb_g_disconnect(musb); in musb_handle_intr_disconnect()
970 musb_hnp_stop(musb); in musb_handle_intr_disconnect()
971 musb_root_disconnect(musb); in musb_handle_intr_disconnect()
976 musb_g_disconnect(musb); in musb_handle_intr_disconnect()
980 musb_otg_state_string(musb)); in musb_handle_intr_disconnect()
989 static void musb_handle_intr_reset(struct musb *musb) in musb_handle_intr_reset() argument
991 if (is_host_active(musb)) { in musb_handle_intr_reset()
994 * platform MUSB is running, because some platforms in musb_handle_intr_reset()
1000 dev_err(musb->controller, "Babble\n"); in musb_handle_intr_reset()
1001 musb_recover_from_babble(musb); in musb_handle_intr_reset()
1003 musb_dbg(musb, "BUS RESET as %s", musb_otg_state_string(musb)); in musb_handle_intr_reset()
1004 switch (musb_get_state(musb)) { in musb_handle_intr_reset()
1006 musb_g_reset(musb); 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()
1011 musb_otg_state_string(musb), in musb_handle_intr_reset()
1012 TA_WAIT_BCON(musb)); in musb_handle_intr_reset()
1013 mod_timer(&musb->otg_timer, jiffies in musb_handle_intr_reset()
1014 + msecs_to_jiffies(TA_WAIT_BCON(musb))); in musb_handle_intr_reset()
1017 del_timer(&musb->otg_timer); in musb_handle_intr_reset()
1018 musb_g_reset(musb); in musb_handle_intr_reset()
1021 musb_dbg(musb, "HNP: RESET (%s), to b_peripheral", in musb_handle_intr_reset()
1022 musb_otg_state_string(musb)); in musb_handle_intr_reset()
1023 musb_set_state(musb, OTG_STATE_B_PERIPHERAL); in musb_handle_intr_reset()
1024 musb_g_reset(musb); in musb_handle_intr_reset()
1027 musb_set_state(musb, OTG_STATE_B_PERIPHERAL); in musb_handle_intr_reset()
1030 musb_g_reset(musb); in musb_handle_intr_reset()
1033 musb_dbg(musb, "Unhandled BUS RESET as %s", in musb_handle_intr_reset()
1034 musb_otg_state_string(musb)); in musb_handle_intr_reset()
1045 * @param musb instance pointer
1050 static irqreturn_t musb_stage0_irq(struct musb *musb, u8 int_usb, in musb_stage0_irq() argument
1055 musb_dbg(musb, "<== DevCtl=%02x, int_usb=0x%x", devctl, int_usb); in musb_stage0_irq()
1062 musb_handle_intr_resume(musb, devctl); in musb_stage0_irq()
1068 if (musb_handle_intr_sessreq(musb, devctl)) in musb_stage0_irq()
1074 musb_handle_intr_vbuserr(musb, devctl); in musb_stage0_irq()
1079 musb_handle_intr_suspend(musb, devctl); in musb_stage0_irq()
1084 musb_handle_intr_connect(musb, devctl, int_usb); in musb_stage0_irq()
1089 musb_handle_intr_disconnect(musb, devctl); in musb_stage0_irq()
1094 musb_handle_intr_reset(musb); in musb_stage0_irq()
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()
1135 musb_h_tx_start(musb, epnum); in musb_stage0_irq()
1137 cppi_hostdma_start(musb, epnum); in musb_stage0_irq()
1143 schedule_delayed_work(&musb->irq_work, 0); in musb_stage0_irq()
1148 /*-------------------------------------------------------------------------*/
1150 static void musb_disable_interrupts(struct musb *musb) in musb_disable_interrupts() argument
1152 void __iomem *mbase = musb->mregs; in musb_disable_interrupts()
1156 musb->intrtxe = 0; in musb_disable_interrupts()
1158 musb->intrrxe = 0; in musb_disable_interrupts()
1167 static void musb_enable_interrupts(struct musb *musb) in musb_enable_interrupts() argument
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()
1183 void musb_start(struct musb *musb) in musb_start() argument
1185 void __iomem *regs = musb->mregs; in musb_start()
1189 musb_dbg(musb, "<== devctl %02x", devctl); in musb_start()
1191 musb_enable_interrupts(musb); 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()
1214 musb_get_state(musb) != OTG_STATE_A_WAIT_BCON && in musb_start()
1216 musb->is_active = 1; in musb_start()
1221 musb_platform_enable(musb); in musb_start()
1232 void musb_stop(struct musb *musb) in musb_stop() argument
1235 musb_platform_disable(musb); in musb_stop()
1236 musb_disable_interrupts(musb); in musb_stop()
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()
1246 musb_platform_try_idle(musb, 0); 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
1379 fifo_setup(struct musb *musb, struct musb_hw_ep *hw_ep, in fifo_setup() argument
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()
1453 static int ep_config_from_table(struct musb *musb) in ep_config_from_table() argument
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()
1500 offset = fifo_setup(musb, hw_ep, &ep0_cfg, 0); 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()
1515 offset = fifo_setup(musb, hw_ep + epn, cfg++, offset); 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
1541 * @param musb the controller
1543 static int ep_config_from_hw(struct musb *musb) in ep_config_from_hw() argument
1547 void __iomem *mbase = musb->mregs; in ep_config_from_hw()
1550 musb_dbg(musb, "<== static silicon ep config"); 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()
1558 ret = musb_read_fifosize(musb, hw_ep, 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()
1587 /* Initialize MUSB (M)HDRC part of the USB hardware subsystem;
1590 static int musb_core_init(u16 musb_type, struct musb *musb) in musb_core_init() argument
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()
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()
1649 musb_configure_ep0(musb); 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()
1656 status = ep_config_from_table(musb); in musb_core_init()
1658 status = ep_config_from_hw(musb); 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()
1690 musb_dbg(musb, "%s: hw_ep %d%s, %smax %d", 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()
1698 musb_dbg(musb, "%s: hw_ep %d%s, %smax %d", 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()
1706 musb_dbg(musb, "hw_ep %d not configured", i); in musb_core_init()
1712 /*-------------------------------------------------------------------------*/
1716 * irq sources (phy, dma, etc) will be handled first, musb->int_* values
1721 irqreturn_t musb_interrupt(struct musb *musb) in musb_interrupt() argument
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()
1733 trace_musb_isr(musb); 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()
1759 if (is_host_active(musb)) in musb_interrupt()
1760 retval |= musb_h_ep0_irq(musb); in musb_interrupt()
1762 retval |= musb_g_ep0_irq(musb); in musb_interrupt()
1765 musb->int_tx &= ~BIT(0); in musb_interrupt()
1768 status = musb->int_tx; in musb_interrupt()
1772 if (is_host_active(musb)) in musb_interrupt()
1773 musb_host_tx(musb, epnum); in musb_interrupt()
1775 musb_g_tx(musb, epnum); in musb_interrupt()
1778 status = musb->int_rx; in musb_interrupt()
1782 if (is_host_active(musb)) in musb_interrupt()
1783 musb_host_rx(musb, epnum); in musb_interrupt()
1785 musb_g_rx(musb, epnum); in musb_interrupt()
1799 void musb_dma_completion(struct musb *musb, u8 epnum, u8 transmit) in musb_dma_completion() argument
1804 if (!is_cppi_enabled(musb)) { in musb_dma_completion()
1806 if (is_host_active(musb)) in musb_dma_completion()
1807 musb_h_ep0_irq(musb); in musb_dma_completion()
1809 musb_g_ep0_irq(musb); in musb_dma_completion()
1814 if (is_host_active(musb)) in musb_dma_completion()
1815 musb_host_tx(musb, epnum); in musb_dma_completion()
1817 musb_g_tx(musb, epnum); in musb_dma_completion()
1820 if (is_host_active(musb)) in musb_dma_completion()
1821 musb_host_rx(musb, epnum); in musb_dma_completion()
1823 musb_g_rx(musb, epnum); in musb_dma_completion()
1836 * musb_mailbox - optional phy notifier function
1847 return -ENODEV; in musb_mailbox()
1851 /*-------------------------------------------------------------------------*/
1856 struct musb *musb = dev_to_musb(dev); in mode_show() local
1860 spin_lock_irqsave(&musb->lock, flags); in mode_show()
1861 ret = sprintf(buf, "%s\n", musb_otg_state_string(musb)); in mode_show()
1862 spin_unlock_irqrestore(&musb->lock, flags); in mode_show()
1871 struct musb *musb = dev_to_musb(dev); in mode_store() local
1875 spin_lock_irqsave(&musb->lock, flags); in mode_store()
1877 status = musb_platform_set_mode(musb, MUSB_HOST); in mode_store()
1879 status = musb_platform_set_mode(musb, MUSB_PERIPHERAL); in mode_store()
1881 status = musb_platform_set_mode(musb, MUSB_OTG); in mode_store()
1883 status = -EINVAL; in mode_store()
1884 spin_unlock_irqrestore(&musb->lock, flags); in mode_store()
1894 struct musb *musb = dev_to_musb(dev); in vbus_store() local
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()
1906 if (musb_get_state(musb) == OTG_STATE_A_WAIT_BCON) in vbus_store()
1907 musb->is_active = 0; in vbus_store()
1908 musb_platform_try_idle(musb, jiffies + msecs_to_jiffies(val)); in vbus_store()
1909 spin_unlock_irqrestore(&musb->lock, flags); in vbus_store()
1917 struct musb *musb = dev_to_musb(dev); in vbus_show() local
1924 spin_lock_irqsave(&musb->lock, flags); in vbus_show()
1925 val = musb->a_wait_bcon; in vbus_show()
1926 vbus = musb_platform_get_vbus_status(musb); in vbus_show()
1928 /* Use default MUSB method by means of DEVCTL register */ in vbus_show()
1929 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in vbus_show()
1936 spin_unlock_irqrestore(&musb->lock, flags); in vbus_show()
1950 struct musb *musb = dev_to_musb(dev); in srp_store() local
1956 return -EINVAL; in srp_store()
1960 musb_g_wakeup(musb); in srp_store()
1972 ATTRIBUTE_GROUPS(musb);
1983 static bool musb_state_needs_recheck(struct musb *musb, u8 devctl, in musb_state_needs_recheck() argument
1986 if (musb->quirk_retries && !musb->flush_irq_work) { in musb_state_needs_recheck()
1987 trace_musb_state(musb, devctl, desc); 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()
1999 * Check the musb devctl session bit to determine if we want to
2004 * elsewhere, proper locking must be implemented for musb->session.
2006 static void musb_pm_runtime_check_session(struct musb *musb) in musb_pm_runtime_check_session() argument
2011 devctl = musb_readb(musb->mregs, MUSB_DEVCTL); in musb_pm_runtime_check_session()
2018 musb_state_needs_recheck(musb, devctl, in musb_pm_runtime_check_session()
2022 if (musb_state_needs_recheck(musb, devctl, in musb_pm_runtime_check_session()
2027 if (musb_state_needs_recheck(musb, devctl, in musb_pm_runtime_check_session()
2030 if (!musb->session) in musb_pm_runtime_check_session()
2032 trace_musb_state(musb, devctl, "Allow PM on possible host mode disconnect"); 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()
2048 trace_musb_state(musb, devctl, "Block PM on active 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()
2064 trace_musb_state(musb, devctl, "Allow PM with no session"); 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()
2075 struct musb *musb = container_of(data, struct musb, irq_work.work); in musb_irq_work() local
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()
2085 musb_pm_runtime_check_session(musb); 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()
2096 static void musb_recover_from_babble(struct musb *musb) in musb_recover_from_babble() argument
2101 musb_disable_interrupts(musb); in musb_recover_from_babble()
2109 ret = musb_platform_recover(musb); in musb_recover_from_babble()
2111 musb_enable_interrupts(musb); in musb_recover_from_babble()
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()
2121 musb_root_disconnect(musb); in musb_recover_from_babble()
2124 * When a babble condition occurs, the musb controller in musb_recover_from_babble()
2127 if (musb->dyn_fifo) in musb_recover_from_babble()
2128 ret = ep_config_from_table(musb); in musb_recover_from_babble()
2130 ret = ep_config_from_hw(musb); in musb_recover_from_babble()
2134 musb_start(musb); in musb_recover_from_babble()
2137 /* --------------------------------------------------------------------------
2141 static struct musb *allocate_instance(struct device *dev, in allocate_instance()
2144 struct musb *musb; in allocate_instance() local
2149 musb = devm_kzalloc(dev, sizeof(*musb), GFP_KERNEL); in allocate_instance()
2150 if (!musb) in allocate_instance()
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()
2174 ret = musb_host_alloc(musb); in allocate_instance()
2178 dev_set_drvdata(dev, musb); in allocate_instance()
2180 return musb; in allocate_instance()
2186 static void musb_free(struct musb *musb) in musb_free() argument
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()
2199 musb_host_free(musb); in musb_free()
2203 int (*callback)(struct musb *musb, void *data);
2211 * musb_queue_resume_work(). Callers must take musb->lock.
2213 static int musb_run_resume_work(struct musb *musb) in musb_run_resume_work() argument
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.
2242 * Note that we cowardly refuse queuing work after musb PM runtime
2243 * resume is done calling musb_run_resume_work() and return -EINPROGRESS
2246 int musb_queue_resume_work(struct musb *musb, in musb_queue_resume_work() argument
2247 int (*callback)(struct musb *musb, void *data), in musb_queue_resume_work() argument
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()
2279 error = callback(musb, data); in musb_queue_resume_work()
2287 struct musb *musb; in musb_deassert_reset() local
2290 musb = container_of(work, struct musb, deassert_reset_work.work); in musb_deassert_reset()
2292 spin_lock_irqsave(&musb->lock, flags); in musb_deassert_reset()
2294 if (musb->port1_status & USB_PORT_STAT_RESET) in musb_deassert_reset()
2295 musb_port_reset(musb, false); 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
2312 struct musb *musb; in musb_init_controller() local
2320 status = -ENODEV; in musb_init_controller()
2325 musb = allocate_instance(dev, plat->config, ctrl); in musb_init_controller()
2326 if (!musb) { 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()
2359 status = musb_platform_init(musb); 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()
2485 musb_platform_disable(musb); in musb_init_controller()
2486 musb_disable_interrupts(musb); in musb_init_controller()
2487 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); in musb_init_controller()
2489 /* MUSB_POWER_SOFTCONN might be already set, JZ4740 does this. */ 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()
2497 /* setup musb parts of the core (especially endpoints) */ in musb_init_controller()
2498 status = musb_core_init(plat->config->multipoint in musb_init_controller()
2500 : MUSB_CONTROLLER_HDRC, musb); 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()
2528 MUSB_DEV_MODE(musb); in musb_init_controller()
2529 musb_set_state(musb, OTG_STATE_B_IDLE); 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()
2536 status = musb_platform_set_mode(musb, MUSB_HOST); in musb_init_controller()
2539 status = musb_gadget_setup(musb); in musb_init_controller()
2542 status = musb_platform_set_mode(musb, MUSB_PERIPHERAL); in musb_init_controller()
2545 status = musb_host_setup(musb, plat->power); in musb_init_controller()
2548 status = musb_gadget_setup(musb); in musb_init_controller()
2550 musb_host_cleanup(musb); in musb_init_controller()
2553 status = musb_platform_set_mode(musb, MUSB_OTG); in musb_init_controller()
2556 dev_err(dev, "unsupported port mode %d\n", musb->port_mode); in musb_init_controller()
2563 musb_init_debugfs(musb); 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()
2589 musb_platform_exit(musb); in musb_init_controller()
2592 dev_err_probe(musb->controller, status, "%s failed\n", __func__); in musb_init_controller()
2594 musb_free(musb); in musb_init_controller()
2602 /*-------------------------------------------------------------------------*/
2609 struct device *dev = &pdev->dev; in musb_probe()
2625 struct device *dev = &pdev->dev; in musb_remove()
2626 struct musb *musb = dev_to_musb(dev); in musb_remove() local
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()
2634 musb_exit_debugfs(musb); 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()
2640 musb_host_cleanup(musb); in musb_remove()
2641 musb_gadget_cleanup(musb); in musb_remove()
2643 musb_platform_disable(musb); in musb_remove()
2644 spin_lock_irqsave(&musb->lock, flags); in musb_remove()
2645 musb_disable_interrupts(musb); in musb_remove()
2646 musb_writeb(musb->mregs, MUSB_DEVCTL, 0); in musb_remove()
2647 spin_unlock_irqrestore(&musb->lock, flags); in musb_remove()
2648 musb_platform_exit(musb); 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()
2657 musb_free(musb); in musb_remove()
2663 static void musb_save_context(struct musb *musb) in musb_save_context() argument
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()
2713 musb_read_txfunaddr(musb, i); in musb_save_context()
2714 musb->context.index_regs[i].txhubaddr = in musb_save_context()
2715 musb_read_txhubaddr(musb, i); in musb_save_context()
2716 musb->context.index_regs[i].txhubport = in musb_save_context()
2717 musb_read_txhubport(musb, i); in musb_save_context()
2719 musb->context.index_regs[i].rxfunaddr = in musb_save_context()
2720 musb_read_rxfunaddr(musb, i); in musb_save_context()
2721 musb->context.index_regs[i].rxhubaddr = in musb_save_context()
2722 musb_read_rxhubaddr(musb, i); in musb_save_context()
2723 musb->context.index_regs[i].rxhubport = in musb_save_context()
2724 musb_read_rxhubport(musb, i); in musb_save_context()
2728 static void musb_restore_context(struct musb *musb) in musb_restore_context() argument
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()
2787 musb_write_txfunaddr(musb, i, in musb_restore_context()
2788 musb->context.index_regs[i].txfunaddr); in musb_restore_context()
2789 musb_write_txhubaddr(musb, i, in musb_restore_context()
2790 musb->context.index_regs[i].txhubaddr); in musb_restore_context()
2791 musb_write_txhubport(musb, i, in musb_restore_context()
2792 musb->context.index_regs[i].txhubport); in musb_restore_context()
2794 musb_write_rxfunaddr(musb, i, in musb_restore_context()
2795 musb->context.index_regs[i].rxfunaddr); in musb_restore_context()
2796 musb_write_rxhubaddr(musb, i, in musb_restore_context()
2797 musb->context.index_regs[i].rxhubaddr); in musb_restore_context()
2798 musb_write_rxhubport(musb, i, 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()
2806 struct musb *musb = dev_to_musb(dev); in musb_suspend() local
2816 musb_platform_disable(musb); in musb_suspend()
2817 musb_disable_interrupts(musb); in musb_suspend()
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()
2831 if (is_peripheral_active(musb)) { in musb_suspend()
2835 } else if (is_host_active(musb)) { in musb_suspend()
2837 * they will even be wakeup-enabled. in musb_suspend()
2841 musb_save_context(musb); in musb_suspend()
2843 spin_unlock_irqrestore(&musb->lock, flags); in musb_suspend()
2849 struct musb *musb = dev_to_musb(dev); in musb_resume() local
2865 musb_restore_context(musb); in musb_resume()
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()
2872 musb_enable_interrupts(musb); in musb_resume()
2873 musb_platform_enable(musb); 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()
2883 error = musb_run_resume_work(musb); 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()
2897 struct musb *musb = dev_to_musb(dev); in musb_runtime_suspend() local
2899 musb_save_context(musb); in musb_runtime_suspend()
2900 musb->is_runtime_suspended = 1; in musb_runtime_suspend()
2907 struct musb *musb = dev_to_musb(dev); in musb_runtime_resume() local
2920 if (!musb->is_initialized) in musb_runtime_resume()
2923 musb_restore_context(musb); in musb_runtime_resume()
2925 spin_lock_irqsave(&musb->lock, flags); in musb_runtime_resume()
2926 error = musb_run_resume_work(musb); 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()