Lines Matching refs:mtu
45 dev_dbg(mep->mtu->dev, "%s fifo:%#x/%#x, start_bit: %d\n", in ep_fifo_alloc()
66 dev_dbg(mep->mtu->dev, "%s size:%#x/%#x, start_bit: %d\n", in ep_fifo_free()
71 static inline void mtu3_ss_func_set(struct mtu3 *mtu, bool enable) in mtu3_ss_func_set() argument
75 mtu3_setbits(mtu->mac_base, U3D_USB3_CONFIG, USB3_EN); in mtu3_ss_func_set()
77 mtu3_clrbits(mtu->mac_base, U3D_USB3_CONFIG, USB3_EN); in mtu3_ss_func_set()
79 dev_dbg(mtu->dev, "USB3_EN = %d\n", !!enable); in mtu3_ss_func_set()
83 static inline void mtu3_hs_softconn_set(struct mtu3 *mtu, bool enable) in mtu3_hs_softconn_set() argument
86 mtu3_setbits(mtu->mac_base, U3D_POWER_MANAGEMENT, in mtu3_hs_softconn_set()
89 mtu3_clrbits(mtu->mac_base, U3D_POWER_MANAGEMENT, in mtu3_hs_softconn_set()
92 dev_dbg(mtu->dev, "SOFTCONN = %d\n", !!enable); in mtu3_hs_softconn_set()
96 static int mtu3_device_enable(struct mtu3 *mtu) in mtu3_device_enable() argument
98 void __iomem *ibase = mtu->ippc_base; in mtu3_device_enable()
103 if (mtu->u3_capable) { in mtu3_device_enable()
113 if (mtu->ssusb->dr_mode == USB_DR_MODE_OTG) { in mtu3_device_enable()
115 if (mtu->u3_capable) in mtu3_device_enable()
120 return ssusb_check_clocks(mtu->ssusb, check_clk); in mtu3_device_enable()
123 static void mtu3_device_disable(struct mtu3 *mtu) in mtu3_device_disable() argument
125 void __iomem *ibase = mtu->ippc_base; in mtu3_device_disable()
127 if (mtu->u3_capable) in mtu3_device_disable()
134 if (mtu->ssusb->dr_mode == USB_DR_MODE_OTG) { in mtu3_device_disable()
136 if (mtu->u3_capable) in mtu3_device_disable()
144 static void mtu3_dev_power_on(struct mtu3 *mtu) in mtu3_dev_power_on() argument
146 void __iomem *ibase = mtu->ippc_base; in mtu3_dev_power_on()
149 if (mtu->u3_capable) in mtu3_dev_power_on()
155 static void mtu3_dev_power_down(struct mtu3 *mtu) in mtu3_dev_power_down() argument
157 void __iomem *ibase = mtu->ippc_base; in mtu3_dev_power_down()
159 if (mtu->u3_capable) in mtu3_dev_power_down()
167 static void mtu3_device_reset(struct mtu3 *mtu) in mtu3_device_reset() argument
169 void __iomem *ibase = mtu->ippc_base; in mtu3_device_reset()
176 static void mtu3_intr_status_clear(struct mtu3 *mtu) in mtu3_intr_status_clear() argument
178 void __iomem *mbase = mtu->mac_base; in mtu3_intr_status_clear()
193 static void mtu3_intr_disable(struct mtu3 *mtu) in mtu3_intr_disable() argument
196 mtu3_writel(mtu->mac_base, U3D_LV1IECR, ~0x0); in mtu3_intr_disable()
198 mtu3_writel(mtu->mac_base, U3D_EPIECR, ~0x0); in mtu3_intr_disable()
199 mtu3_intr_status_clear(mtu); in mtu3_intr_disable()
203 static void mtu3_intr_enable(struct mtu3 *mtu) in mtu3_intr_enable() argument
205 void __iomem *mbase = mtu->mac_base; in mtu3_intr_enable()
216 if (mtu->u3_capable) { in mtu3_intr_enable()
232 static void mtu3_set_speed(struct mtu3 *mtu, enum usb_device_speed speed) in mtu3_set_speed() argument
234 void __iomem *mbase = mtu->mac_base; in mtu3_set_speed()
236 if (speed > mtu->max_speed) in mtu3_set_speed()
237 speed = mtu->max_speed; in mtu3_set_speed()
253 mtu3_clrbits(mtu->ippc_base, SSUSB_U3_CTRL(0), in mtu3_set_speed()
258 mtu3_setbits(mtu->ippc_base, SSUSB_U3_CTRL(0), in mtu3_set_speed()
262 dev_err(mtu->dev, "invalid speed: %s\n", in mtu3_set_speed()
267 mtu->speed = speed; in mtu3_set_speed()
268 dev_dbg(mtu->dev, "set speed: %s\n", usb_speed_string(speed)); in mtu3_set_speed()
272 static void mtu3_csr_init(struct mtu3 *mtu) in mtu3_csr_init() argument
274 void __iomem *mbase = mtu->mac_base; in mtu3_csr_init()
276 if (mtu->u3_capable) { in mtu3_csr_init()
300 struct mtu3 *mtu = mep->mtu; in mtu3_ep_reset() local
303 mtu3_setbits(mtu->mac_base, U3D_EP_RST, rst_bit); in mtu3_ep_reset()
304 mtu3_clrbits(mtu->mac_base, U3D_EP_RST, rst_bit); in mtu3_ep_reset()
310 struct mtu3 *mtu = mep->mtu; in mtu3_ep_stall_set() local
311 void __iomem *mbase = mtu->mac_base; in mtu3_ep_stall_set()
338 dev_dbg(mtu->dev, "%s: %s\n", mep->name, in mtu3_ep_stall_set()
342 void mtu3_dev_on_off(struct mtu3 *mtu, int is_on) in mtu3_dev_on_off() argument
344 if (mtu->u3_capable && mtu->speed >= USB_SPEED_SUPER) in mtu3_dev_on_off()
345 mtu3_ss_func_set(mtu, is_on); in mtu3_dev_on_off()
347 mtu3_hs_softconn_set(mtu, is_on); in mtu3_dev_on_off()
349 dev_info(mtu->dev, "gadget (%s) pullup D%s\n", in mtu3_dev_on_off()
350 usb_speed_string(mtu->speed), is_on ? "+" : "-"); in mtu3_dev_on_off()
353 void mtu3_start(struct mtu3 *mtu) in mtu3_start() argument
355 void __iomem *mbase = mtu->mac_base; in mtu3_start()
357 dev_dbg(mtu->dev, "%s devctl 0x%x\n", __func__, in mtu3_start()
360 mtu3_dev_power_on(mtu); in mtu3_start()
361 mtu3_csr_init(mtu); in mtu3_start()
362 mtu3_set_speed(mtu, mtu->speed); in mtu3_start()
365 mtu3_intr_enable(mtu); in mtu3_start()
366 mtu->is_active = 1; in mtu3_start()
368 if (mtu->softconnect) in mtu3_start()
369 mtu3_dev_on_off(mtu, 1); in mtu3_start()
372 void mtu3_stop(struct mtu3 *mtu) in mtu3_stop() argument
374 dev_dbg(mtu->dev, "%s\n", __func__); in mtu3_stop()
376 mtu3_intr_disable(mtu); in mtu3_stop()
378 if (mtu->softconnect) in mtu3_stop()
379 mtu3_dev_on_off(mtu, 0); in mtu3_stop()
381 mtu->is_active = 0; in mtu3_stop()
382 mtu3_dev_power_down(mtu); in mtu3_stop()
385 static void mtu3_dev_suspend(struct mtu3 *mtu) in mtu3_dev_suspend() argument
387 if (!mtu->is_active) in mtu3_dev_suspend()
390 mtu3_intr_disable(mtu); in mtu3_dev_suspend()
391 mtu3_dev_power_down(mtu); in mtu3_dev_suspend()
394 static void mtu3_dev_resume(struct mtu3 *mtu) in mtu3_dev_resume() argument
396 if (!mtu->is_active) in mtu3_dev_resume()
399 mtu3_dev_power_on(mtu); in mtu3_dev_resume()
400 mtu3_intr_enable(mtu); in mtu3_dev_resume()
404 int mtu3_config_ep(struct mtu3 *mtu, struct mtu3_ep *mep, in mtu3_config_ep() argument
407 void __iomem *mbase = mtu->mac_base; in mtu3_config_ep()
408 bool gen2cp = mtu->gen2cp; in mtu3_config_ep()
416 dev_err(mtu->dev, "alloc ep fifo failed(%d)\n", mep->maxp); in mtu3_config_ep()
420 dev_dbg(mtu->dev, "%s fifosz: %x(%x/%x)\n", __func__, fifo_sgsz, in mtu3_config_ep()
455 dev_dbg(mtu->dev, "U3D_TX%d CSR0:%#x, CSR1:%#x, CSR2:%#x\n", in mtu3_config_ep()
491 dev_dbg(mtu->dev, "U3D_RX%d CSR0:%#x, CSR1:%#x, CSR2:%#x\n", in mtu3_config_ep()
497 dev_dbg(mtu->dev, "csr0:%#x, csr1:%#x, csr2:%#x\n", csr0, csr1, csr2); in mtu3_config_ep()
498 dev_dbg(mtu->dev, "%s: %s, fifo-addr:%#x, fifo-size:%#x(%#x/%#x)\n", in mtu3_config_ep()
506 void mtu3_deconfig_ep(struct mtu3 *mtu, struct mtu3_ep *mep) in mtu3_deconfig_ep() argument
508 void __iomem *mbase = mtu->mac_base; in mtu3_deconfig_ep()
526 dev_dbg(mtu->dev, "%s: %s\n", __func__, mep->name); in mtu3_deconfig_ep()
541 static void get_ep_fifo_config(struct mtu3 *mtu) in get_ep_fifo_config() argument
547 if (mtu->separate_fifo) { in get_ep_fifo_config()
548 fifosize = mtu3_readl(mtu->mac_base, U3D_CAP_EPNTXFFSZ); in get_ep_fifo_config()
549 tx_fifo = &mtu->tx_fifo; in get_ep_fifo_config()
554 fifosize = mtu3_readl(mtu->mac_base, U3D_CAP_EPNRXFFSZ); in get_ep_fifo_config()
555 rx_fifo = &mtu->rx_fifo; in get_ep_fifo_config()
559 mtu->slot = MTU3_U3_IP_SLOT_DEFAULT; in get_ep_fifo_config()
561 fifosize = mtu3_readl(mtu->mac_base, U3D_CAP_EPNTXFFSZ); in get_ep_fifo_config()
562 tx_fifo = &mtu->tx_fifo; in get_ep_fifo_config()
567 rx_fifo = &mtu->rx_fifo; in get_ep_fifo_config()
572 mtu->slot = MTU3_U2_IP_SLOT_DEFAULT; in get_ep_fifo_config()
575 dev_dbg(mtu->dev, "%s, TX: base-%d, limit-%d; RX: base-%d, limit-%d\n", in get_ep_fifo_config()
580 static void mtu3_ep0_setup(struct mtu3 *mtu) in mtu3_ep0_setup() argument
582 u32 maxpacket = mtu->g.ep0->maxpacket; in mtu3_ep0_setup()
585 dev_dbg(mtu->dev, "%s maxpacket: %d\n", __func__, maxpacket); in mtu3_ep0_setup()
587 csr = mtu3_readl(mtu->mac_base, U3D_EP0CSR); in mtu3_ep0_setup()
591 mtu3_writel(mtu->mac_base, U3D_EP0CSR, csr); in mtu3_ep0_setup()
594 mtu3_writel(mtu->mac_base, U3D_EPIESR, EP0ISR | SETUPENDISR); in mtu3_ep0_setup()
597 static int mtu3_mem_alloc(struct mtu3 *mtu) in mtu3_mem_alloc() argument
599 void __iomem *mbase = mtu->mac_base; in mtu3_mem_alloc()
610 dev_info(mtu->dev, "fifosz/epnum: Tx=%#x/%d, Rx=%#x/%d\n", in mtu3_mem_alloc()
615 mtu->num_eps = min(in_ep_num, out_ep_num) + 1; in mtu3_mem_alloc()
616 ep_array = kcalloc(mtu->num_eps * 2, sizeof(*ep_array), GFP_KERNEL); in mtu3_mem_alloc()
620 mtu->ep_array = ep_array; in mtu3_mem_alloc()
621 mtu->in_eps = ep_array; in mtu3_mem_alloc()
622 mtu->out_eps = &ep_array[mtu->num_eps]; in mtu3_mem_alloc()
624 mtu->ep0 = mtu->in_eps; in mtu3_mem_alloc()
625 mtu->ep0->mtu = mtu; in mtu3_mem_alloc()
626 mtu->ep0->epnum = 0; in mtu3_mem_alloc()
628 for (i = 1; i < mtu->num_eps; i++) { in mtu3_mem_alloc()
629 struct mtu3_ep *mep = mtu->in_eps + i; in mtu3_mem_alloc()
631 mep->fifo = &mtu->tx_fifo; in mtu3_mem_alloc()
632 mep = mtu->out_eps + i; in mtu3_mem_alloc()
633 mep->fifo = &mtu->rx_fifo; in mtu3_mem_alloc()
636 get_ep_fifo_config(mtu); in mtu3_mem_alloc()
638 ret = mtu3_qmu_init(mtu); in mtu3_mem_alloc()
640 kfree(mtu->ep_array); in mtu3_mem_alloc()
645 static void mtu3_mem_free(struct mtu3 *mtu) in mtu3_mem_free() argument
647 mtu3_qmu_exit(mtu); in mtu3_mem_free()
648 kfree(mtu->ep_array); in mtu3_mem_free()
651 static void mtu3_regs_init(struct mtu3 *mtu) in mtu3_regs_init() argument
653 void __iomem *mbase = mtu->mac_base; in mtu3_regs_init()
656 mtu3_intr_disable(mtu); in mtu3_regs_init()
658 mtu3_csr_init(mtu); in mtu3_regs_init()
665 if (mtu->gen2cp) in mtu3_regs_init()
669 static irqreturn_t mtu3_link_isr(struct mtu3 *mtu) in mtu3_link_isr() argument
671 void __iomem *mbase = mtu->mac_base; in mtu3_link_isr()
680 dev_dbg(mtu->dev, "=== LINK[%x] ===\n", link); in mtu3_link_isr()
716 dev_dbg(mtu->dev, "%s: %s\n", __func__, usb_speed_string(udev_speed)); in mtu3_link_isr()
717 mtu3_dbg_trace(mtu->dev, "link speed %s", in mtu3_link_isr()
720 mtu->g.speed = udev_speed; in mtu3_link_isr()
721 mtu->g.ep0->maxpacket = maxpkt; in mtu3_link_isr()
722 mtu->ep0_state = MU3D_EP0_STATE_SETUP; in mtu3_link_isr()
723 mtu->connected = !!(udev_speed != USB_SPEED_UNKNOWN); in mtu3_link_isr()
726 mtu3_gadget_disconnect(mtu); in mtu3_link_isr()
727 pm_runtime_put(mtu->dev); in mtu3_link_isr()
729 pm_runtime_get(mtu->dev); in mtu3_link_isr()
730 mtu3_ep0_setup(mtu); in mtu3_link_isr()
736 static irqreturn_t mtu3_u3_ltssm_isr(struct mtu3 *mtu) in mtu3_u3_ltssm_isr() argument
738 void __iomem *mbase = mtu->mac_base; in mtu3_u3_ltssm_isr()
744 dev_dbg(mtu->dev, "=== LTSSM[%x] ===\n", ltssm); in mtu3_u3_ltssm_isr()
748 mtu3_gadget_reset(mtu); in mtu3_u3_ltssm_isr()
751 mtu3_ss_func_set(mtu, false); in mtu3_u3_ltssm_isr()
752 mtu3_gadget_reset(mtu); in mtu3_u3_ltssm_isr()
756 mtu3_ss_func_set(mtu, true); in mtu3_u3_ltssm_isr()
759 mtu3_gadget_resume(mtu); in mtu3_u3_ltssm_isr()
762 mtu3_gadget_suspend(mtu); in mtu3_u3_ltssm_isr()
767 static irqreturn_t mtu3_u2_common_isr(struct mtu3 *mtu) in mtu3_u2_common_isr() argument
769 void __iomem *mbase = mtu->mac_base; in mtu3_u2_common_isr()
775 dev_dbg(mtu->dev, "=== U2COMM[%x] ===\n", u2comm); in mtu3_u2_common_isr()
779 mtu3_gadget_suspend(mtu); in mtu3_u2_common_isr()
782 mtu3_gadget_resume(mtu); in mtu3_u2_common_isr()
785 mtu3_gadget_reset(mtu); in mtu3_u2_common_isr()
792 struct mtu3 *mtu = (struct mtu3 *)data; in mtu3_irq() local
796 spin_lock_irqsave(&mtu->lock, flags); in mtu3_irq()
799 level1 = mtu3_readl(mtu->mac_base, U3D_LV1ISR); in mtu3_irq()
800 level1 &= mtu3_readl(mtu->mac_base, U3D_LV1IER); in mtu3_irq()
803 mtu3_link_isr(mtu); in mtu3_irq()
806 mtu3_u2_common_isr(mtu); in mtu3_irq()
809 mtu3_u3_ltssm_isr(mtu); in mtu3_irq()
812 mtu3_ep0_isr(mtu); in mtu3_irq()
815 mtu3_qmu_isr(mtu); in mtu3_irq()
817 spin_unlock_irqrestore(&mtu->lock, flags); in mtu3_irq()
822 static void mtu3_check_params(struct mtu3 *mtu) in mtu3_check_params() argument
825 if (mtu->u3_capable && (mtu->ssusb->u3p_dis_msk & BIT(0))) in mtu3_check_params()
826 mtu->u3_capable = 0; in mtu3_check_params()
829 switch (mtu->max_speed) { in mtu3_check_params()
836 dev_err(mtu->dev, "invalid max_speed: %s\n", in mtu3_check_params()
837 usb_speed_string(mtu->max_speed)); in mtu3_check_params()
841 mtu->max_speed = USB_SPEED_SUPER_PLUS; in mtu3_check_params()
845 if (!mtu->u3_capable && (mtu->max_speed > USB_SPEED_HIGH)) in mtu3_check_params()
846 mtu->max_speed = USB_SPEED_HIGH; in mtu3_check_params()
848 mtu->speed = mtu->max_speed; in mtu3_check_params()
850 dev_info(mtu->dev, "max_speed: %s\n", in mtu3_check_params()
851 usb_speed_string(mtu->max_speed)); in mtu3_check_params()
854 static int mtu3_hw_init(struct mtu3 *mtu) in mtu3_hw_init() argument
859 value = mtu3_readl(mtu->ippc_base, U3D_SSUSB_IP_TRUNK_VERS); in mtu3_hw_init()
860 mtu->hw_version = IP_TRUNK_VERS(value); in mtu3_hw_init()
861 mtu->gen2cp = !!(mtu->hw_version >= MTU3_TRUNK_VERS_1003); in mtu3_hw_init()
863 value = mtu3_readl(mtu->ippc_base, U3D_SSUSB_IP_DEV_CAP); in mtu3_hw_init()
864 mtu->u3_capable = !!SSUSB_IP_DEV_U3_PORT_NUM(value); in mtu3_hw_init()
866 mtu->separate_fifo = mtu->u3_capable; in mtu3_hw_init()
868 dev_info(mtu->dev, "IP version 0x%x(%s IP)\n", mtu->hw_version, in mtu3_hw_init()
869 mtu->u3_capable ? "U3" : "U2"); in mtu3_hw_init()
871 mtu3_check_params(mtu); in mtu3_hw_init()
873 mtu3_device_reset(mtu); in mtu3_hw_init()
875 ret = mtu3_device_enable(mtu); in mtu3_hw_init()
877 dev_err(mtu->dev, "device enable failed %d\n", ret); in mtu3_hw_init()
881 ret = mtu3_mem_alloc(mtu); in mtu3_hw_init()
885 mtu3_regs_init(mtu); in mtu3_hw_init()
890 static void mtu3_hw_exit(struct mtu3 *mtu) in mtu3_hw_exit() argument
892 mtu3_device_disable(mtu); in mtu3_hw_exit()
893 mtu3_mem_free(mtu); in mtu3_hw_exit()
900 static int mtu3_set_dma_mask(struct mtu3 *mtu) in mtu3_set_dma_mask() argument
902 struct device *dev = mtu->dev; in mtu3_set_dma_mask()
907 value = mtu3_readl(mtu->mac_base, U3D_MISC_CTRL); in mtu3_set_dma_mask()
926 struct mtu3 *mtu = NULL; in ssusb_gadget_init() local
929 mtu = devm_kzalloc(dev, sizeof(struct mtu3), GFP_KERNEL); in ssusb_gadget_init()
930 if (mtu == NULL) in ssusb_gadget_init()
933 mtu->irq = platform_get_irq_byname_optional(pdev, "device"); in ssusb_gadget_init()
934 if (mtu->irq < 0) { in ssusb_gadget_init()
935 if (mtu->irq == -EPROBE_DEFER) in ssusb_gadget_init()
936 return mtu->irq; in ssusb_gadget_init()
939 mtu->irq = platform_get_irq(pdev, 0); in ssusb_gadget_init()
940 if (mtu->irq < 0) in ssusb_gadget_init()
941 return mtu->irq; in ssusb_gadget_init()
943 dev_info(dev, "irq %d\n", mtu->irq); in ssusb_gadget_init()
945 mtu->mac_base = devm_platform_ioremap_resource_byname(pdev, "mac"); in ssusb_gadget_init()
946 if (IS_ERR(mtu->mac_base)) { in ssusb_gadget_init()
948 return PTR_ERR(mtu->mac_base); in ssusb_gadget_init()
951 spin_lock_init(&mtu->lock); in ssusb_gadget_init()
952 mtu->dev = dev; in ssusb_gadget_init()
953 mtu->ippc_base = ssusb->ippc_base; in ssusb_gadget_init()
954 ssusb->mac_base = mtu->mac_base; in ssusb_gadget_init()
955 ssusb->u3d = mtu; in ssusb_gadget_init()
956 mtu->ssusb = ssusb; in ssusb_gadget_init()
957 mtu->max_speed = usb_get_maximum_speed(dev); in ssusb_gadget_init()
960 mtu->mac_base, mtu->ippc_base); in ssusb_gadget_init()
962 ret = mtu3_hw_init(mtu); in ssusb_gadget_init()
968 ret = mtu3_set_dma_mask(mtu); in ssusb_gadget_init()
974 ret = devm_request_threaded_irq(dev, mtu->irq, NULL, mtu3_irq, in ssusb_gadget_init()
975 IRQF_ONESHOT, dev_name(dev), mtu); in ssusb_gadget_init()
977 dev_err(dev, "request irq %d failed!\n", mtu->irq); in ssusb_gadget_init()
982 mtu3_stop(mtu); in ssusb_gadget_init()
984 ret = mtu3_gadget_setup(mtu); in ssusb_gadget_init()
1001 mtu3_hw_exit(mtu); in ssusb_gadget_init()
1010 struct mtu3 *mtu = ssusb->u3d; in ssusb_gadget_exit() local
1012 mtu3_gadget_cleanup(mtu); in ssusb_gadget_exit()
1014 mtu3_hw_exit(mtu); in ssusb_gadget_exit()
1019 struct mtu3 *mtu = ssusb->u3d; in ssusb_gadget_ip_sleep_check() local
1022 if (!mtu) in ssusb_gadget_ip_sleep_check()
1026 if (mtu->is_active && mtu->softconnect) in ssusb_gadget_ip_sleep_check()
1035 struct mtu3 *mtu = ssusb->u3d; in ssusb_gadget_suspend() local
1037 if (!mtu->gadget_driver) in ssusb_gadget_suspend()
1040 if (mtu->connected) in ssusb_gadget_suspend()
1043 mtu3_dev_suspend(mtu); in ssusb_gadget_suspend()
1044 synchronize_irq(mtu->irq); in ssusb_gadget_suspend()
1051 struct mtu3 *mtu = ssusb->u3d; in ssusb_gadget_resume() local
1053 if (!mtu->gadget_driver) in ssusb_gadget_resume()
1056 mtu3_dev_resume(mtu); in ssusb_gadget_resume()