Lines Matching +full:tegra210 +full:- +full:xudc
1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2013-2022, NVIDIA CORPORATION. All rights reserved.
12 #include <linux/dma-mapping.h>
246 return (le32_to_cpu(ctx->member) >> (shift)) & (mask); \
253 tmp = le32_to_cpu(ctx->member) & ~((mask) << (shift)); \
255 ctx->member = cpu_to_le32(tmp); \
338 return (le32_to_cpu(trb->member) >> (shift)) & (mask); \
345 tmp = le32_to_cpu(trb->member) & ~((mask) << (shift)); \
347 trb->member = cpu_to_le32(tmp); \
396 struct tegra_xudc *xudc; member
560 static inline u32 fpci_readl(struct tegra_xudc *xudc, unsigned int offset) in fpci_readl() argument
562 return readl(xudc->fpci + offset); in fpci_readl()
565 static inline void fpci_writel(struct tegra_xudc *xudc, u32 val, in fpci_writel() argument
568 writel(val, xudc->fpci + offset); in fpci_writel()
571 static inline u32 ipfs_readl(struct tegra_xudc *xudc, unsigned int offset) in ipfs_readl() argument
573 return readl(xudc->ipfs + offset); in ipfs_readl()
576 static inline void ipfs_writel(struct tegra_xudc *xudc, u32 val, in ipfs_writel() argument
579 writel(val, xudc->ipfs + offset); in ipfs_writel()
582 static inline u32 xudc_readl(struct tegra_xudc *xudc, unsigned int offset) in xudc_readl() argument
584 return readl(xudc->base + offset); in xudc_readl()
587 static inline void xudc_writel(struct tegra_xudc *xudc, u32 val, in xudc_writel() argument
590 writel(val, xudc->base + offset); in xudc_writel()
593 static inline int xudc_readl_poll(struct tegra_xudc *xudc, in xudc_readl_poll() argument
598 return readl_poll_timeout_atomic(xudc->base + offset, regval, in xudc_readl_poll()
617 static inline void dump_trb(struct tegra_xudc *xudc, const char *type, in dump_trb() argument
620 dev_dbg(xudc->dev, in dump_trb()
622 type, trb, trb->data_lo, trb->data_hi, trb->status, in dump_trb()
623 trb->control); in dump_trb()
626 static void tegra_xudc_limit_port_speed(struct tegra_xudc *xudc) in tegra_xudc_limit_port_speed() argument
631 val = xudc_readl(xudc, SSPX_CORE_CNT56); in tegra_xudc_limit_port_speed()
634 xudc_writel(xudc, val, SSPX_CORE_CNT56); in tegra_xudc_limit_port_speed()
636 val = xudc_readl(xudc, SSPX_CORE_CNT57); in tegra_xudc_limit_port_speed()
639 xudc_writel(xudc, val, SSPX_CORE_CNT57); in tegra_xudc_limit_port_speed()
641 val = xudc_readl(xudc, SSPX_CORE_CNT65); in tegra_xudc_limit_port_speed()
644 xudc_writel(xudc, val, SSPX_CORE_CNT66); in tegra_xudc_limit_port_speed()
646 val = xudc_readl(xudc, SSPX_CORE_CNT66); in tegra_xudc_limit_port_speed()
649 xudc_writel(xudc, val, SSPX_CORE_CNT66); in tegra_xudc_limit_port_speed()
651 val = xudc_readl(xudc, SSPX_CORE_CNT67); in tegra_xudc_limit_port_speed()
654 xudc_writel(xudc, val, SSPX_CORE_CNT67); in tegra_xudc_limit_port_speed()
656 val = xudc_readl(xudc, SSPX_CORE_CNT72); in tegra_xudc_limit_port_speed()
659 xudc_writel(xudc, val, SSPX_CORE_CNT72); in tegra_xudc_limit_port_speed()
662 static void tegra_xudc_restore_port_speed(struct tegra_xudc *xudc) in tegra_xudc_restore_port_speed() argument
667 val = xudc_readl(xudc, SSPX_CORE_CNT56); in tegra_xudc_restore_port_speed()
670 xudc_writel(xudc, val, SSPX_CORE_CNT56); in tegra_xudc_restore_port_speed()
672 val = xudc_readl(xudc, SSPX_CORE_CNT57); in tegra_xudc_restore_port_speed()
675 xudc_writel(xudc, val, SSPX_CORE_CNT57); in tegra_xudc_restore_port_speed()
677 val = xudc_readl(xudc, SSPX_CORE_CNT65); in tegra_xudc_restore_port_speed()
680 xudc_writel(xudc, val, SSPX_CORE_CNT66); in tegra_xudc_restore_port_speed()
682 val = xudc_readl(xudc, SSPX_CORE_CNT66); in tegra_xudc_restore_port_speed()
685 xudc_writel(xudc, val, SSPX_CORE_CNT66); in tegra_xudc_restore_port_speed()
687 val = xudc_readl(xudc, SSPX_CORE_CNT67); in tegra_xudc_restore_port_speed()
690 xudc_writel(xudc, val, SSPX_CORE_CNT67); in tegra_xudc_restore_port_speed()
692 val = xudc_readl(xudc, SSPX_CORE_CNT72); in tegra_xudc_restore_port_speed()
695 xudc_writel(xudc, val, SSPX_CORE_CNT72); in tegra_xudc_restore_port_speed()
698 static void tegra_xudc_device_mode_on(struct tegra_xudc *xudc) in tegra_xudc_device_mode_on() argument
702 pm_runtime_get_sync(xudc->dev); in tegra_xudc_device_mode_on()
704 tegra_phy_xusb_utmi_pad_power_on(xudc->curr_utmi_phy); in tegra_xudc_device_mode_on()
706 err = phy_power_on(xudc->curr_utmi_phy); in tegra_xudc_device_mode_on()
708 dev_err(xudc->dev, "UTMI power on failed: %d\n", err); in tegra_xudc_device_mode_on()
710 err = phy_power_on(xudc->curr_usb3_phy); in tegra_xudc_device_mode_on()
712 dev_err(xudc->dev, "USB3 PHY power on failed: %d\n", err); in tegra_xudc_device_mode_on()
714 dev_dbg(xudc->dev, "device mode on\n"); in tegra_xudc_device_mode_on()
716 phy_set_mode_ext(xudc->curr_utmi_phy, PHY_MODE_USB_OTG, in tegra_xudc_device_mode_on()
720 static void tegra_xudc_device_mode_off(struct tegra_xudc *xudc) in tegra_xudc_device_mode_off() argument
726 dev_dbg(xudc->dev, "device mode off\n"); in tegra_xudc_device_mode_off()
728 connected = !!(xudc_readl(xudc, PORTSC) & PORTSC_CCS); in tegra_xudc_device_mode_off()
730 reinit_completion(&xudc->disconnect_complete); in tegra_xudc_device_mode_off()
732 if (xudc->soc->port_speed_quirk) in tegra_xudc_device_mode_off()
733 tegra_xudc_restore_port_speed(xudc); in tegra_xudc_device_mode_off()
735 phy_set_mode_ext(xudc->curr_utmi_phy, PHY_MODE_USB_OTG, USB_ROLE_NONE); in tegra_xudc_device_mode_off()
737 pls = (xudc_readl(xudc, PORTSC) & PORTSC_PLS_MASK) >> in tegra_xudc_device_mode_off()
741 if (xudc->soc->pls_quirk && xudc->gadget.speed == USB_SPEED_SUPER && in tegra_xudc_device_mode_off()
743 val = xudc_readl(xudc, PORTPM); in tegra_xudc_device_mode_off()
745 xudc_writel(xudc, val, PORTPM); in tegra_xudc_device_mode_off()
747 val = xudc_readl(xudc, PORTSC); in tegra_xudc_device_mode_off()
750 xudc_writel(xudc, val, PORTSC); in tegra_xudc_device_mode_off()
755 wait_for_completion(&xudc->disconnect_complete); in tegra_xudc_device_mode_off()
758 synchronize_irq(xudc->irq); in tegra_xudc_device_mode_off()
760 tegra_phy_xusb_utmi_pad_power_down(xudc->curr_utmi_phy); in tegra_xudc_device_mode_off()
762 err = phy_power_off(xudc->curr_utmi_phy); in tegra_xudc_device_mode_off()
764 dev_err(xudc->dev, "UTMI PHY power off failed: %d\n", err); in tegra_xudc_device_mode_off()
766 err = phy_power_off(xudc->curr_usb3_phy); in tegra_xudc_device_mode_off()
768 dev_err(xudc->dev, "USB3 PHY power off failed: %d\n", err); in tegra_xudc_device_mode_off()
770 pm_runtime_put(xudc->dev); in tegra_xudc_device_mode_off()
775 struct tegra_xudc *xudc = container_of(work, struct tegra_xudc, in tegra_xudc_usb_role_sw_work() local
778 if (xudc->device_mode) in tegra_xudc_usb_role_sw_work()
779 tegra_xudc_device_mode_on(xudc); in tegra_xudc_usb_role_sw_work()
781 tegra_xudc_device_mode_off(xudc); in tegra_xudc_usb_role_sw_work()
784 static int tegra_xudc_get_phy_index(struct tegra_xudc *xudc, in tegra_xudc_get_phy_index() argument
789 for (i = 0; i < xudc->soc->num_phys; i++) { in tegra_xudc_get_phy_index()
790 if (xudc->usbphy[i] && usbphy == xudc->usbphy[i]) in tegra_xudc_get_phy_index()
794 dev_info(xudc->dev, "phy index could not be found for shared USB PHY"); in tegra_xudc_get_phy_index()
795 return -1; in tegra_xudc_get_phy_index()
798 static void tegra_xudc_update_data_role(struct tegra_xudc *xudc, in tegra_xudc_update_data_role() argument
803 if ((xudc->device_mode && usbphy->last_event == USB_EVENT_VBUS) || in tegra_xudc_update_data_role()
804 (!xudc->device_mode && usbphy->last_event != USB_EVENT_VBUS)) { in tegra_xudc_update_data_role()
805 dev_dbg(xudc->dev, "Same role(%d) received. Ignore", in tegra_xudc_update_data_role()
806 xudc->device_mode); in tegra_xudc_update_data_role()
810 xudc->device_mode = (usbphy->last_event == USB_EVENT_VBUS) ? true : in tegra_xudc_update_data_role()
813 phy_index = tegra_xudc_get_phy_index(xudc, usbphy); in tegra_xudc_update_data_role()
814 dev_dbg(xudc->dev, "%s(): current phy index is %d\n", __func__, in tegra_xudc_update_data_role()
817 if (!xudc->suspended && phy_index != -1) { in tegra_xudc_update_data_role()
818 xudc->curr_utmi_phy = xudc->utmi_phy[phy_index]; in tegra_xudc_update_data_role()
819 xudc->curr_usb3_phy = xudc->usb3_phy[phy_index]; in tegra_xudc_update_data_role()
820 xudc->curr_usbphy = usbphy; in tegra_xudc_update_data_role()
821 schedule_work(&xudc->usb_role_sw_work); in tegra_xudc_update_data_role()
828 struct tegra_xudc *xudc = container_of(nb, struct tegra_xudc, in tegra_xudc_vbus_notify() local
832 dev_dbg(xudc->dev, "%s(): event is %d\n", __func__, usbphy->last_event); in tegra_xudc_vbus_notify()
834 tegra_xudc_update_data_role(xudc, usbphy); in tegra_xudc_vbus_notify()
842 struct tegra_xudc *xudc = container_of(dwork, struct tegra_xudc, in tegra_xudc_plc_reset_work() local
846 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_plc_reset_work()
848 if (xudc->wait_csc) { in tegra_xudc_plc_reset_work()
849 u32 pls = (xudc_readl(xudc, PORTSC) & PORTSC_PLS_MASK) >> in tegra_xudc_plc_reset_work()
853 dev_info(xudc->dev, "PLS = Inactive. Toggle VBUS\n"); in tegra_xudc_plc_reset_work()
854 phy_set_mode_ext(xudc->curr_utmi_phy, PHY_MODE_USB_OTG, in tegra_xudc_plc_reset_work()
856 phy_set_mode_ext(xudc->curr_utmi_phy, PHY_MODE_USB_OTG, in tegra_xudc_plc_reset_work()
859 xudc->wait_csc = false; in tegra_xudc_plc_reset_work()
863 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_plc_reset_work()
869 struct tegra_xudc *xudc = in tegra_xudc_port_reset_war_work() local
875 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_port_reset_war_work()
877 if (xudc->device_mode && xudc->wait_for_sec_prc) { in tegra_xudc_port_reset_war_work()
878 pls = (xudc_readl(xudc, PORTSC) & PORTSC_PLS_MASK) >> in tegra_xudc_port_reset_war_work()
880 dev_dbg(xudc->dev, "pls = %x\n", pls); in tegra_xudc_port_reset_war_work()
883 dev_dbg(xudc->dev, "toggle vbus\n"); in tegra_xudc_port_reset_war_work()
886 xudc->curr_utmi_phy); in tegra_xudc_port_reset_war_work()
888 xudc->wait_for_sec_prc = 0; in tegra_xudc_port_reset_war_work()
892 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_port_reset_war_work()
900 index = trb - ep->transfer_ring; in trb_virt_to_phys()
905 return (ep->transfer_ring_phys + index * sizeof(*trb)); in trb_virt_to_phys()
914 index = (addr - ep->transfer_ring_phys) / sizeof(*trb); in trb_phys_to_virt()
919 trb = &ep->transfer_ring[index]; in trb_phys_to_virt()
924 static void ep_reload(struct tegra_xudc *xudc, unsigned int ep) in ep_reload() argument
926 xudc_writel(xudc, BIT(ep), EP_RELOAD); in ep_reload()
927 xudc_readl_poll(xudc, EP_RELOAD, BIT(ep), 0); in ep_reload()
930 static void ep_pause(struct tegra_xudc *xudc, unsigned int ep) in ep_pause() argument
934 val = xudc_readl(xudc, EP_PAUSE); in ep_pause()
939 xudc_writel(xudc, val, EP_PAUSE); in ep_pause()
941 xudc_readl_poll(xudc, EP_STCHG, BIT(ep), BIT(ep)); in ep_pause()
943 xudc_writel(xudc, BIT(ep), EP_STCHG); in ep_pause()
946 static void ep_unpause(struct tegra_xudc *xudc, unsigned int ep) in ep_unpause() argument
950 val = xudc_readl(xudc, EP_PAUSE); in ep_unpause()
955 xudc_writel(xudc, val, EP_PAUSE); in ep_unpause()
957 xudc_readl_poll(xudc, EP_STCHG, BIT(ep), BIT(ep)); in ep_unpause()
959 xudc_writel(xudc, BIT(ep), EP_STCHG); in ep_unpause()
962 static void ep_unpause_all(struct tegra_xudc *xudc) in ep_unpause_all() argument
966 val = xudc_readl(xudc, EP_PAUSE); in ep_unpause_all()
968 xudc_writel(xudc, 0, EP_PAUSE); in ep_unpause_all()
970 xudc_readl_poll(xudc, EP_STCHG, val, val); in ep_unpause_all()
972 xudc_writel(xudc, val, EP_STCHG); in ep_unpause_all()
975 static void ep_halt(struct tegra_xudc *xudc, unsigned int ep) in ep_halt() argument
979 val = xudc_readl(xudc, EP_HALT); in ep_halt()
983 xudc_writel(xudc, val, EP_HALT); in ep_halt()
985 xudc_readl_poll(xudc, EP_STCHG, BIT(ep), BIT(ep)); in ep_halt()
987 xudc_writel(xudc, BIT(ep), EP_STCHG); in ep_halt()
990 static void ep_unhalt(struct tegra_xudc *xudc, unsigned int ep) in ep_unhalt() argument
994 val = xudc_readl(xudc, EP_HALT); in ep_unhalt()
998 xudc_writel(xudc, val, EP_HALT); in ep_unhalt()
1000 xudc_readl_poll(xudc, EP_STCHG, BIT(ep), BIT(ep)); in ep_unhalt()
1002 xudc_writel(xudc, BIT(ep), EP_STCHG); in ep_unhalt()
1005 static void ep_unhalt_all(struct tegra_xudc *xudc) in ep_unhalt_all() argument
1009 val = xudc_readl(xudc, EP_HALT); in ep_unhalt_all()
1012 xudc_writel(xudc, 0, EP_HALT); in ep_unhalt_all()
1014 xudc_readl_poll(xudc, EP_STCHG, val, val); in ep_unhalt_all()
1016 xudc_writel(xudc, val, EP_STCHG); in ep_unhalt_all()
1019 static void ep_wait_for_stopped(struct tegra_xudc *xudc, unsigned int ep) in ep_wait_for_stopped() argument
1021 xudc_readl_poll(xudc, EP_STOPPED, BIT(ep), BIT(ep)); in ep_wait_for_stopped()
1022 xudc_writel(xudc, BIT(ep), EP_STOPPED); in ep_wait_for_stopped()
1025 static void ep_wait_for_inactive(struct tegra_xudc *xudc, unsigned int ep) in ep_wait_for_inactive() argument
1027 xudc_readl_poll(xudc, EP_THREAD_ACTIVE, BIT(ep), 0); in ep_wait_for_inactive()
1033 struct tegra_xudc *xudc = ep->xudc; in tegra_xudc_req_done() local
1035 dev_dbg(xudc->dev, "completing request %p on EP %u with status %d\n", in tegra_xudc_req_done()
1036 req, ep->index, status); in tegra_xudc_req_done()
1038 if (likely(req->usb_req.status == -EINPROGRESS)) in tegra_xudc_req_done()
1039 req->usb_req.status = status; in tegra_xudc_req_done()
1041 list_del_init(&req->list); in tegra_xudc_req_done()
1043 if (usb_endpoint_xfer_control(ep->desc)) { in tegra_xudc_req_done()
1044 usb_gadget_unmap_request(&xudc->gadget, &req->usb_req, in tegra_xudc_req_done()
1045 (xudc->setup_state == in tegra_xudc_req_done()
1048 usb_gadget_unmap_request(&xudc->gadget, &req->usb_req, in tegra_xudc_req_done()
1049 usb_endpoint_dir_in(ep->desc)); in tegra_xudc_req_done()
1052 spin_unlock(&xudc->lock); in tegra_xudc_req_done()
1053 usb_gadget_giveback_request(&ep->usb_ep, &req->usb_req); in tegra_xudc_req_done()
1054 spin_lock(&xudc->lock); in tegra_xudc_req_done()
1061 while (!list_empty(&ep->queue)) { in tegra_xudc_ep_nuke()
1062 req = list_first_entry(&ep->queue, struct tegra_xudc_request, in tegra_xudc_ep_nuke()
1070 if (ep->ring_full) in ep_available_trbs()
1073 if (ep->deq_ptr > ep->enq_ptr) in ep_available_trbs()
1074 return ep->deq_ptr - ep->enq_ptr - 1; in ep_available_trbs()
1076 return XUDC_TRANSFER_RING_SIZE - (ep->enq_ptr - ep->deq_ptr) - 2; in ep_available_trbs()
1084 struct tegra_xudc *xudc = ep->xudc; in tegra_xudc_queue_one_trb() local
1088 len = min_t(size_t, XUDC_TRB_MAX_BUFFER_SIZE, req->usb_req.length - in tegra_xudc_queue_one_trb()
1089 req->buf_queued); in tegra_xudc_queue_one_trb()
1091 buf_addr = req->usb_req.dma + req->buf_queued; in tegra_xudc_queue_one_trb()
1098 trb_write_td_size(trb, req->trbs_needed - req->trbs_queued - 1); in tegra_xudc_queue_one_trb()
1100 if (req->trbs_queued == req->trbs_needed - 1 || in tegra_xudc_queue_one_trb()
1101 (req->need_zlp && req->trbs_queued == req->trbs_needed - 2)) in tegra_xudc_queue_one_trb()
1108 if (usb_endpoint_dir_out(ep->desc) || in tegra_xudc_queue_one_trb()
1109 (usb_endpoint_xfer_control(ep->desc) && in tegra_xudc_queue_one_trb()
1110 (xudc->setup_state == DATA_STAGE_RECV))) in tegra_xudc_queue_one_trb()
1115 if (usb_endpoint_xfer_control(ep->desc)) { in tegra_xudc_queue_one_trb()
1116 if (xudc->setup_state == DATA_STAGE_XFER || in tegra_xudc_queue_one_trb()
1117 xudc->setup_state == DATA_STAGE_RECV) in tegra_xudc_queue_one_trb()
1122 if (xudc->setup_state == DATA_STAGE_XFER || in tegra_xudc_queue_one_trb()
1123 xudc->setup_state == STATUS_STAGE_XFER) in tegra_xudc_queue_one_trb()
1127 } else if (usb_endpoint_xfer_isoc(ep->desc)) { in tegra_xudc_queue_one_trb()
1132 } else if (usb_ss_max_streams(ep->comp_desc)) { in tegra_xudc_queue_one_trb()
1134 trb_write_stream_id(trb, req->usb_req.stream_id); in tegra_xudc_queue_one_trb()
1140 trb_write_cycle(trb, ep->pcs); in tegra_xudc_queue_one_trb()
1142 req->trbs_queued++; in tegra_xudc_queue_one_trb()
1143 req->buf_queued += len; in tegra_xudc_queue_one_trb()
1145 dump_trb(xudc, "TRANSFER", trb); in tegra_xudc_queue_one_trb()
1155 count = req->trbs_needed - req->trbs_queued; in tegra_xudc_queue_trbs()
1158 ep->ring_full = true; in tegra_xudc_queue_trbs()
1162 * To generate zero-length packet on USB bus, SW needs schedule a in tegra_xudc_queue_trbs()
1163 * standalone zero-length TD. According to HW's behavior, SW needs in tegra_xudc_queue_trbs()
1167 * - Data stage TD (IOC = 1, CH = 0) in tegra_xudc_queue_trbs()
1168 * - Ring doorbell and wait transfer event in tegra_xudc_queue_trbs()
1169 * - Data stage TD for ZLP (IOC = 1, CH = 0) in tegra_xudc_queue_trbs()
1170 * - Ring doorbell in tegra_xudc_queue_trbs()
1173 * - Normal transfer TD (IOC = 0, CH = 0) in tegra_xudc_queue_trbs()
1174 * - Normal transfer TD for ZLP (IOC = 1, CH = 0) in tegra_xudc_queue_trbs()
1175 * - Ring doorbell in tegra_xudc_queue_trbs()
1178 if (req->need_zlp && usb_endpoint_xfer_control(ep->desc) && count > 1) in tegra_xudc_queue_trbs()
1181 if (!req->first_trb) in tegra_xudc_queue_trbs()
1182 req->first_trb = &ep->transfer_ring[ep->enq_ptr]; in tegra_xudc_queue_trbs()
1185 struct tegra_xudc_trb *trb = &ep->transfer_ring[ep->enq_ptr]; in tegra_xudc_queue_trbs()
1188 if ((i == count - 1) || (wait_td && i == count - 2)) in tegra_xudc_queue_trbs()
1192 req->last_trb = trb; in tegra_xudc_queue_trbs()
1194 ep->enq_ptr++; in tegra_xudc_queue_trbs()
1195 if (ep->enq_ptr == XUDC_TRANSFER_RING_SIZE - 1) { in tegra_xudc_queue_trbs()
1196 trb = &ep->transfer_ring[ep->enq_ptr]; in tegra_xudc_queue_trbs()
1197 trb_write_cycle(trb, ep->pcs); in tegra_xudc_queue_trbs()
1198 ep->pcs = !ep->pcs; in tegra_xudc_queue_trbs()
1199 ep->enq_ptr = 0; in tegra_xudc_queue_trbs()
1211 struct tegra_xudc *xudc = ep->xudc; in tegra_xudc_ep_ring_doorbell() local
1214 if (list_empty(&ep->queue)) in tegra_xudc_ep_ring_doorbell()
1217 val = DB_TARGET(ep->index); in tegra_xudc_ep_ring_doorbell()
1218 if (usb_endpoint_xfer_control(ep->desc)) { in tegra_xudc_ep_ring_doorbell()
1219 val |= DB_STREAMID(xudc->setup_seq_num); in tegra_xudc_ep_ring_doorbell()
1220 } else if (usb_ss_max_streams(ep->comp_desc) > 0) { in tegra_xudc_ep_ring_doorbell()
1224 if (ep->stream_rejected) in tegra_xudc_ep_ring_doorbell()
1227 req = list_first_entry(&ep->queue, struct tegra_xudc_request, in tegra_xudc_ep_ring_doorbell()
1229 val |= DB_STREAMID(req->usb_req.stream_id); in tegra_xudc_ep_ring_doorbell()
1232 dev_dbg(xudc->dev, "ring doorbell: %#x\n", val); in tegra_xudc_ep_ring_doorbell()
1233 xudc_writel(xudc, val, DB); in tegra_xudc_ep_ring_doorbell()
1241 list_for_each_entry(req, &ep->queue, list) { in tegra_xudc_ep_kick_queue()
1242 if (ep->ring_full) in tegra_xudc_ep_kick_queue()
1256 struct tegra_xudc *xudc = ep->xudc; in __tegra_xudc_ep_queue() local
1259 if (usb_endpoint_xfer_control(ep->desc) && !list_empty(&ep->queue)) { in __tegra_xudc_ep_queue()
1260 dev_err(xudc->dev, "control EP has pending transfers\n"); in __tegra_xudc_ep_queue()
1261 return -EINVAL; in __tegra_xudc_ep_queue()
1264 if (usb_endpoint_xfer_control(ep->desc)) { in __tegra_xudc_ep_queue()
1265 err = usb_gadget_map_request(&xudc->gadget, &req->usb_req, in __tegra_xudc_ep_queue()
1266 (xudc->setup_state == in __tegra_xudc_ep_queue()
1269 err = usb_gadget_map_request(&xudc->gadget, &req->usb_req, in __tegra_xudc_ep_queue()
1270 usb_endpoint_dir_in(ep->desc)); in __tegra_xudc_ep_queue()
1274 dev_err(xudc->dev, "failed to map request: %d\n", err); in __tegra_xudc_ep_queue()
1278 req->first_trb = NULL; in __tegra_xudc_ep_queue()
1279 req->last_trb = NULL; in __tegra_xudc_ep_queue()
1280 req->buf_queued = 0; in __tegra_xudc_ep_queue()
1281 req->trbs_queued = 0; in __tegra_xudc_ep_queue()
1282 req->need_zlp = false; in __tegra_xudc_ep_queue()
1283 req->trbs_needed = DIV_ROUND_UP(req->usb_req.length, in __tegra_xudc_ep_queue()
1285 if (req->usb_req.length == 0) in __tegra_xudc_ep_queue()
1286 req->trbs_needed++; in __tegra_xudc_ep_queue()
1288 if (!usb_endpoint_xfer_isoc(ep->desc) && in __tegra_xudc_ep_queue()
1289 req->usb_req.zero && req->usb_req.length && in __tegra_xudc_ep_queue()
1290 ((req->usb_req.length % ep->usb_ep.maxpacket) == 0)) { in __tegra_xudc_ep_queue()
1291 req->trbs_needed++; in __tegra_xudc_ep_queue()
1292 req->need_zlp = true; in __tegra_xudc_ep_queue()
1295 req->usb_req.status = -EINPROGRESS; in __tegra_xudc_ep_queue()
1296 req->usb_req.actual = 0; in __tegra_xudc_ep_queue()
1298 list_add_tail(&req->list, &ep->queue); in __tegra_xudc_ep_queue()
1311 struct tegra_xudc *xudc; in tegra_xudc_ep_queue() local
1316 return -EINVAL; in tegra_xudc_ep_queue()
1320 xudc = ep->xudc; in tegra_xudc_ep_queue()
1322 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_ep_queue()
1323 if (xudc->powergated || !ep->desc) { in tegra_xudc_ep_queue()
1324 ret = -ESHUTDOWN; in tegra_xudc_ep_queue()
1330 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_ep_queue()
1338 struct tegra_xudc_trb *trb = req->first_trb; in squeeze_transfer_ring()
1344 * and must correct trb cycle bit to the last un-enqueued state. in squeeze_transfer_ring()
1346 while (trb != &ep->transfer_ring[ep->enq_ptr]) { in squeeze_transfer_ring()
1353 trb = ep->transfer_ring; in squeeze_transfer_ring()
1356 /* Requests will be re-queued at the start of the cancelled request. */ in squeeze_transfer_ring()
1357 ep->enq_ptr = req->first_trb - ep->transfer_ring; in squeeze_transfer_ring()
1362 ep->pcs = pcs_enq; in squeeze_transfer_ring()
1363 ep->ring_full = false; in squeeze_transfer_ring()
1364 list_for_each_entry_continue(req, &ep->queue, list) { in squeeze_transfer_ring()
1365 req->usb_req.status = -EINPROGRESS; in squeeze_transfer_ring()
1366 req->usb_req.actual = 0; in squeeze_transfer_ring()
1368 req->first_trb = NULL; in squeeze_transfer_ring()
1369 req->last_trb = NULL; in squeeze_transfer_ring()
1370 req->buf_queued = 0; in squeeze_transfer_ring()
1371 req->trbs_queued = 0; in squeeze_transfer_ring()
1383 dev_dbg(ep->xudc->dev, "%s: request %p -> %p; trb %p\n", __func__, in trb_in_request()
1384 req->first_trb, req->last_trb, trb); in trb_in_request()
1386 if (trb >= req->first_trb && (trb <= req->last_trb || in trb_in_request()
1387 req->last_trb < req->first_trb)) in trb_in_request()
1390 if (trb < req->first_trb && trb <= req->last_trb && in trb_in_request()
1391 req->last_trb < req->first_trb) in trb_in_request()
1405 struct tegra_xudc_trb *enq_trb = &ep->transfer_ring[ep->enq_ptr]; in trb_before_request()
1407 dev_dbg(ep->xudc->dev, "%s: request %p -> %p; enq ptr: %p; trb %p\n", in trb_before_request()
1408 __func__, req->first_trb, req->last_trb, enq_trb, trb); in trb_before_request()
1410 if (trb < req->first_trb && (enq_trb <= trb || in trb_before_request()
1411 req->first_trb < enq_trb)) in trb_before_request()
1414 if (trb > req->first_trb && req->first_trb < enq_trb && enq_trb <= trb) in trb_before_request()
1424 struct tegra_xudc *xudc = ep->xudc; in __tegra_xudc_ep_dequeue() local
1431 list_for_each_entry(iter, &ep->queue, list) { in __tegra_xudc_ep_dequeue()
1439 return -EINVAL; in __tegra_xudc_ep_dequeue()
1442 if (!req->trbs_queued) { in __tegra_xudc_ep_dequeue()
1443 tegra_xudc_req_done(ep, req, -ECONNRESET); in __tegra_xudc_ep_dequeue()
1448 if (ep_ctx_read_state(ep->context) == EP_STATE_RUNNING) { in __tegra_xudc_ep_dequeue()
1449 ep_pause(xudc, ep->index); in __tegra_xudc_ep_dequeue()
1450 ep_wait_for_inactive(xudc, ep->index); in __tegra_xudc_ep_dequeue()
1453 deq_trb = trb_phys_to_virt(ep, ep_ctx_read_deq_ptr(ep->context)); in __tegra_xudc_ep_dequeue()
1455 busy = (trb_read_cycle(deq_trb) == ep_ctx_read_dcs(ep->context)); in __tegra_xudc_ep_dequeue()
1466 req->usb_req.actual = ep_ctx_read_edtla(ep->context); in __tegra_xudc_ep_dequeue()
1467 tegra_xudc_req_done(ep, req, -ECONNRESET); in __tegra_xudc_ep_dequeue()
1471 if (req->usb_req.actual > 0) { in __tegra_xudc_ep_dequeue()
1476 ep_ctx_write_edtla(ep->context, 0); in __tegra_xudc_ep_dequeue()
1477 ep_ctx_write_partial_td(ep->context, 0); in __tegra_xudc_ep_dequeue()
1478 ep_ctx_write_data_offset(ep->context, 0); in __tegra_xudc_ep_dequeue()
1481 &ep->transfer_ring[ep->enq_ptr]); in __tegra_xudc_ep_dequeue()
1483 if (dma_mapping_error(xudc->dev, deq_ptr)) { in __tegra_xudc_ep_dequeue()
1484 ret = -EINVAL; in __tegra_xudc_ep_dequeue()
1486 ep_ctx_write_deq_ptr(ep->context, deq_ptr); in __tegra_xudc_ep_dequeue()
1487 ep_ctx_write_dcs(ep->context, ep->pcs); in __tegra_xudc_ep_dequeue()
1488 ep_reload(xudc, ep->index); in __tegra_xudc_ep_dequeue()
1495 tegra_xudc_req_done(ep, req, -ECONNRESET); in __tegra_xudc_ep_dequeue()
1502 tegra_xudc_req_done(ep, req, -ECONNRESET); in __tegra_xudc_ep_dequeue()
1503 ret = -EINVAL; in __tegra_xudc_ep_dequeue()
1507 ep_unpause(xudc, ep->index); in __tegra_xudc_ep_dequeue()
1520 struct tegra_xudc *xudc; in tegra_xudc_ep_dequeue() local
1525 return -EINVAL; in tegra_xudc_ep_dequeue()
1529 xudc = ep->xudc; in tegra_xudc_ep_dequeue()
1531 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_ep_dequeue()
1533 if (xudc->powergated || !ep->desc) { in tegra_xudc_ep_dequeue()
1534 ret = -ESHUTDOWN; in tegra_xudc_ep_dequeue()
1540 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_ep_dequeue()
1547 struct tegra_xudc *xudc = ep->xudc; in __tegra_xudc_ep_set_halt() local
1549 if (!ep->desc) in __tegra_xudc_ep_set_halt()
1550 return -EINVAL; in __tegra_xudc_ep_set_halt()
1552 if (usb_endpoint_xfer_isoc(ep->desc)) { in __tegra_xudc_ep_set_halt()
1553 dev_err(xudc->dev, "can't halt isochronous EP\n"); in __tegra_xudc_ep_set_halt()
1554 return -ENOTSUPP; in __tegra_xudc_ep_set_halt()
1557 if (!!(xudc_readl(xudc, EP_HALT) & BIT(ep->index)) == halt) { in __tegra_xudc_ep_set_halt()
1558 dev_dbg(xudc->dev, "EP %u already %s\n", ep->index, in __tegra_xudc_ep_set_halt()
1564 ep_halt(xudc, ep->index); in __tegra_xudc_ep_set_halt()
1566 ep_ctx_write_state(ep->context, EP_STATE_DISABLED); in __tegra_xudc_ep_set_halt()
1568 ep_reload(xudc, ep->index); in __tegra_xudc_ep_set_halt()
1570 ep_ctx_write_state(ep->context, EP_STATE_RUNNING); in __tegra_xudc_ep_set_halt()
1571 ep_ctx_write_rsvd(ep->context, 0); in __tegra_xudc_ep_set_halt()
1572 ep_ctx_write_partial_td(ep->context, 0); in __tegra_xudc_ep_set_halt()
1573 ep_ctx_write_splitxstate(ep->context, 0); in __tegra_xudc_ep_set_halt()
1574 ep_ctx_write_seq_num(ep->context, 0); in __tegra_xudc_ep_set_halt()
1576 ep_reload(xudc, ep->index); in __tegra_xudc_ep_set_halt()
1577 ep_unpause(xudc, ep->index); in __tegra_xudc_ep_set_halt()
1578 ep_unhalt(xudc, ep->index); in __tegra_xudc_ep_set_halt()
1589 struct tegra_xudc *xudc; in tegra_xudc_ep_set_halt() local
1594 return -EINVAL; in tegra_xudc_ep_set_halt()
1597 xudc = ep->xudc; in tegra_xudc_ep_set_halt()
1599 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_ep_set_halt()
1600 if (xudc->powergated) { in tegra_xudc_ep_set_halt()
1601 ret = -ESHUTDOWN; in tegra_xudc_ep_set_halt()
1605 if (value && usb_endpoint_dir_in(ep->desc) && in tegra_xudc_ep_set_halt()
1606 !list_empty(&ep->queue)) { in tegra_xudc_ep_set_halt()
1607 dev_err(xudc->dev, "can't halt EP with requests pending\n"); in tegra_xudc_ep_set_halt()
1608 ret = -EAGAIN; in tegra_xudc_ep_set_halt()
1614 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_ep_set_halt()
1621 const struct usb_endpoint_descriptor *desc = ep->desc; in tegra_xudc_ep_context_setup()
1622 const struct usb_ss_ep_comp_descriptor *comp_desc = ep->comp_desc; in tegra_xudc_ep_context_setup()
1623 struct tegra_xudc *xudc = ep->xudc; in tegra_xudc_ep_context_setup() local
1628 if (xudc->gadget.speed == USB_SPEED_SUPER) { in tegra_xudc_ep_context_setup()
1630 maxburst = comp_desc->bMaxBurst; in tegra_xudc_ep_context_setup()
1633 esit = le16_to_cpu(comp_desc->wBytesPerInterval); in tegra_xudc_ep_context_setup()
1634 } else if ((xudc->gadget.speed < USB_SPEED_SUPER) && in tegra_xudc_ep_context_setup()
1637 if (xudc->gadget.speed == USB_SPEED_HIGH) { in tegra_xudc_ep_context_setup()
1638 maxburst = usb_endpoint_maxp_mult(desc) - 1; in tegra_xudc_ep_context_setup()
1640 dev_warn(xudc->dev, in tegra_xudc_ep_context_setup()
1648 memset(ep->context, 0, sizeof(*ep->context)); in tegra_xudc_ep_context_setup()
1650 ep_ctx_write_state(ep->context, EP_STATE_RUNNING); in tegra_xudc_ep_context_setup()
1651 ep_ctx_write_interval(ep->context, desc->bInterval); in tegra_xudc_ep_context_setup()
1652 if (xudc->gadget.speed == USB_SPEED_SUPER) { in tegra_xudc_ep_context_setup()
1654 ep_ctx_write_mult(ep->context, in tegra_xudc_ep_context_setup()
1655 comp_desc->bmAttributes & 0x3); in tegra_xudc_ep_context_setup()
1659 ep_ctx_write_max_pstreams(ep->context, in tegra_xudc_ep_context_setup()
1660 comp_desc->bmAttributes & in tegra_xudc_ep_context_setup()
1662 ep_ctx_write_lsa(ep->context, 1); in tegra_xudc_ep_context_setup()
1671 ep_ctx_write_type(ep->context, val); in tegra_xudc_ep_context_setup()
1672 ep_ctx_write_cerr(ep->context, 0x3); in tegra_xudc_ep_context_setup()
1673 ep_ctx_write_max_packet_size(ep->context, maxpacket); in tegra_xudc_ep_context_setup()
1674 ep_ctx_write_max_burst_size(ep->context, maxburst); in tegra_xudc_ep_context_setup()
1676 ep_ctx_write_deq_ptr(ep->context, ep->transfer_ring_phys); in tegra_xudc_ep_context_setup()
1677 ep_ctx_write_dcs(ep->context, ep->pcs); in tegra_xudc_ep_context_setup()
1694 ep_ctx_write_avg_trb_len(ep->context, val); in tegra_xudc_ep_context_setup()
1695 ep_ctx_write_max_esit_payload(ep->context, esit); in tegra_xudc_ep_context_setup()
1697 ep_ctx_write_cerrcnt(ep->context, 0x3); in tegra_xudc_ep_context_setup()
1703 trb_write_data_ptr(trb, ep->transfer_ring_phys); in setup_link_trb()
1710 struct tegra_xudc *xudc = ep->xudc; in __tegra_xudc_ep_disable() local
1712 if (ep_ctx_read_state(ep->context) == EP_STATE_DISABLED) { in __tegra_xudc_ep_disable()
1713 dev_err(xudc->dev, "endpoint %u already disabled\n", in __tegra_xudc_ep_disable()
1714 ep->index); in __tegra_xudc_ep_disable()
1715 return -EINVAL; in __tegra_xudc_ep_disable()
1718 ep_ctx_write_state(ep->context, EP_STATE_DISABLED); in __tegra_xudc_ep_disable()
1720 ep_reload(xudc, ep->index); in __tegra_xudc_ep_disable()
1722 tegra_xudc_ep_nuke(ep, -ESHUTDOWN); in __tegra_xudc_ep_disable()
1724 xudc->nr_enabled_eps--; in __tegra_xudc_ep_disable()
1725 if (usb_endpoint_xfer_isoc(ep->desc)) in __tegra_xudc_ep_disable()
1726 xudc->nr_isoch_eps--; in __tegra_xudc_ep_disable()
1728 ep->desc = NULL; in __tegra_xudc_ep_disable()
1729 ep->comp_desc = NULL; in __tegra_xudc_ep_disable()
1731 memset(ep->context, 0, sizeof(*ep->context)); in __tegra_xudc_ep_disable()
1733 ep_unpause(xudc, ep->index); in __tegra_xudc_ep_disable()
1734 ep_unhalt(xudc, ep->index); in __tegra_xudc_ep_disable()
1735 if (xudc_readl(xudc, EP_STOPPED) & BIT(ep->index)) in __tegra_xudc_ep_disable()
1736 xudc_writel(xudc, BIT(ep->index), EP_STOPPED); in __tegra_xudc_ep_disable()
1739 * If this is the last endpoint disabled in a de-configure request, in __tegra_xudc_ep_disable()
1742 if ((xudc->device_state == USB_STATE_CONFIGURED) && in __tegra_xudc_ep_disable()
1743 (xudc->nr_enabled_eps == 1)) { in __tegra_xudc_ep_disable()
1746 xudc->device_state = USB_STATE_ADDRESS; in __tegra_xudc_ep_disable()
1747 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in __tegra_xudc_ep_disable()
1749 val = xudc_readl(xudc, CTRL); in __tegra_xudc_ep_disable()
1751 xudc_writel(xudc, val, CTRL); in __tegra_xudc_ep_disable()
1754 dev_info(xudc->dev, "ep %u disabled\n", ep->index); in __tegra_xudc_ep_disable()
1762 struct tegra_xudc *xudc; in tegra_xudc_ep_disable() local
1767 return -EINVAL; in tegra_xudc_ep_disable()
1770 xudc = ep->xudc; in tegra_xudc_ep_disable()
1772 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_ep_disable()
1773 if (xudc->powergated) { in tegra_xudc_ep_disable()
1774 ret = -ESHUTDOWN; in tegra_xudc_ep_disable()
1780 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_ep_disable()
1788 struct tegra_xudc *xudc = ep->xudc; in __tegra_xudc_ep_enable() local
1792 if (xudc->gadget.speed == USB_SPEED_SUPER && in __tegra_xudc_ep_enable()
1793 !usb_endpoint_xfer_control(desc) && !ep->usb_ep.comp_desc) in __tegra_xudc_ep_enable()
1794 return -EINVAL; in __tegra_xudc_ep_enable()
1797 if (ep_ctx_read_state(ep->context) != EP_STATE_DISABLED) in __tegra_xudc_ep_enable()
1800 ep->desc = desc; in __tegra_xudc_ep_enable()
1801 ep->comp_desc = ep->usb_ep.comp_desc; in __tegra_xudc_ep_enable()
1804 if (xudc->nr_isoch_eps > XUDC_MAX_ISOCH_EPS) { in __tegra_xudc_ep_enable()
1805 dev_err(xudc->dev, "too many isochronous endpoints\n"); in __tegra_xudc_ep_enable()
1806 return -EBUSY; in __tegra_xudc_ep_enable()
1808 xudc->nr_isoch_eps++; in __tegra_xudc_ep_enable()
1811 memset(ep->transfer_ring, 0, XUDC_TRANSFER_RING_SIZE * in __tegra_xudc_ep_enable()
1812 sizeof(*ep->transfer_ring)); in __tegra_xudc_ep_enable()
1813 setup_link_trb(ep, &ep->transfer_ring[XUDC_TRANSFER_RING_SIZE - 1]); in __tegra_xudc_ep_enable()
1815 ep->enq_ptr = 0; in __tegra_xudc_ep_enable()
1816 ep->deq_ptr = 0; in __tegra_xudc_ep_enable()
1817 ep->pcs = true; in __tegra_xudc_ep_enable()
1818 ep->ring_full = false; in __tegra_xudc_ep_enable()
1819 xudc->nr_enabled_eps++; in __tegra_xudc_ep_enable()
1824 * No need to reload and un-halt EP0. This will be done automatically in __tegra_xudc_ep_enable()
1831 * Transition to configured state once the first non-control in __tegra_xudc_ep_enable()
1834 if (xudc->device_state == USB_STATE_ADDRESS) { in __tegra_xudc_ep_enable()
1835 val = xudc_readl(xudc, CTRL); in __tegra_xudc_ep_enable()
1837 xudc_writel(xudc, val, CTRL); in __tegra_xudc_ep_enable()
1839 xudc->device_state = USB_STATE_CONFIGURED; in __tegra_xudc_ep_enable()
1840 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in __tegra_xudc_ep_enable()
1848 for (i = 0; i < ARRAY_SIZE(xudc->ep); i++) { in __tegra_xudc_ep_enable()
1849 if (xudc->ep[i].desc && in __tegra_xudc_ep_enable()
1850 usb_endpoint_xfer_bulk(xudc->ep[i].desc)) in __tegra_xudc_ep_enable()
1851 ep_pause(xudc, i); in __tegra_xudc_ep_enable()
1855 ep_reload(xudc, ep->index); in __tegra_xudc_ep_enable()
1856 ep_unpause(xudc, ep->index); in __tegra_xudc_ep_enable()
1857 ep_unhalt(xudc, ep->index); in __tegra_xudc_ep_enable()
1860 for (i = 0; i < ARRAY_SIZE(xudc->ep); i++) { in __tegra_xudc_ep_enable()
1861 if (xudc->ep[i].desc && in __tegra_xudc_ep_enable()
1862 usb_endpoint_xfer_bulk(xudc->ep[i].desc)) in __tegra_xudc_ep_enable()
1863 ep_unpause(xudc, i); in __tegra_xudc_ep_enable()
1868 dev_info(xudc->dev, "EP %u (type: %s, dir: %s) enabled\n", ep->index, in __tegra_xudc_ep_enable()
1869 usb_ep_type_string(usb_endpoint_type(ep->desc)), in __tegra_xudc_ep_enable()
1870 usb_endpoint_dir_in(ep->desc) ? "in" : "out"); in __tegra_xudc_ep_enable()
1879 struct tegra_xudc *xudc; in tegra_xudc_ep_enable() local
1883 if (!usb_ep || !desc || (desc->bDescriptorType != USB_DT_ENDPOINT)) in tegra_xudc_ep_enable()
1884 return -EINVAL; in tegra_xudc_ep_enable()
1887 xudc = ep->xudc; in tegra_xudc_ep_enable()
1889 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_ep_enable()
1890 if (xudc->powergated) { in tegra_xudc_ep_enable()
1891 ret = -ESHUTDOWN; in tegra_xudc_ep_enable()
1897 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_ep_enable()
1911 INIT_LIST_HEAD(&req->list); in tegra_xudc_ep_alloc_request()
1913 return &req->usb_req; in tegra_xudc_ep_alloc_request()
1937 return -EBUSY; in tegra_xudc_ep0_enable()
1942 return -EBUSY; in tegra_xudc_ep0_disable()
1957 struct tegra_xudc *xudc = to_xudc(gadget); in tegra_xudc_gadget_get_frame() local
1961 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_gadget_get_frame()
1962 if (xudc->powergated) { in tegra_xudc_gadget_get_frame()
1963 ret = -ESHUTDOWN; in tegra_xudc_gadget_get_frame()
1967 ret = (xudc_readl(xudc, MFINDEX) & MFINDEX_FRAME_MASK) >> in tegra_xudc_gadget_get_frame()
1970 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_gadget_get_frame()
1975 static void tegra_xudc_resume_device_state(struct tegra_xudc *xudc) in tegra_xudc_resume_device_state() argument
1980 ep_unpause_all(xudc); in tegra_xudc_resume_device_state()
1983 val = xudc_readl(xudc, PORTSC); in tegra_xudc_resume_device_state()
1987 xudc_writel(xudc, val, PORTSC); in tegra_xudc_resume_device_state()
1990 if (xudc->device_state == USB_STATE_SUSPENDED) { in tegra_xudc_resume_device_state()
1991 xudc->device_state = xudc->resume_state; in tegra_xudc_resume_device_state()
1992 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in tegra_xudc_resume_device_state()
1993 xudc->resume_state = 0; in tegra_xudc_resume_device_state()
2001 for (i = 0; i < ARRAY_SIZE(xudc->ep); i++) in tegra_xudc_resume_device_state()
2002 tegra_xudc_ep_ring_doorbell(&xudc->ep[i]); in tegra_xudc_resume_device_state()
2007 struct tegra_xudc *xudc = to_xudc(gadget); in tegra_xudc_gadget_wakeup() local
2012 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_gadget_wakeup()
2014 if (xudc->powergated) { in tegra_xudc_gadget_wakeup()
2015 ret = -ESHUTDOWN; in tegra_xudc_gadget_wakeup()
2018 val = xudc_readl(xudc, PORTPM); in tegra_xudc_gadget_wakeup()
2019 dev_dbg(xudc->dev, "%s: PORTPM=%#x, speed=%x\n", __func__, in tegra_xudc_gadget_wakeup()
2020 val, gadget->speed); in tegra_xudc_gadget_wakeup()
2022 if (((xudc->gadget.speed <= USB_SPEED_HIGH) && in tegra_xudc_gadget_wakeup()
2024 ((xudc->gadget.speed == USB_SPEED_SUPER) && in tegra_xudc_gadget_wakeup()
2026 tegra_xudc_resume_device_state(xudc); in tegra_xudc_gadget_wakeup()
2029 if (xudc->gadget.speed == USB_SPEED_SUPER) { in tegra_xudc_gadget_wakeup()
2032 xudc_writel(xudc, 0, DEVNOTIF_HI); in tegra_xudc_gadget_wakeup()
2033 xudc_writel(xudc, val, DEVNOTIF_LO); in tegra_xudc_gadget_wakeup()
2038 dev_dbg(xudc->dev, "%s: ret value is %d", __func__, ret); in tegra_xudc_gadget_wakeup()
2039 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_gadget_wakeup()
2046 struct tegra_xudc *xudc = to_xudc(gadget); in tegra_xudc_gadget_pullup() local
2050 pm_runtime_get_sync(xudc->dev); in tegra_xudc_gadget_pullup()
2052 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_gadget_pullup()
2054 if (is_on != xudc->pullup) { in tegra_xudc_gadget_pullup()
2055 val = xudc_readl(xudc, CTRL); in tegra_xudc_gadget_pullup()
2060 xudc_writel(xudc, val, CTRL); in tegra_xudc_gadget_pullup()
2063 xudc->pullup = is_on; in tegra_xudc_gadget_pullup()
2064 dev_dbg(xudc->dev, "%s: pullup:%d", __func__, is_on); in tegra_xudc_gadget_pullup()
2066 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_gadget_pullup()
2068 pm_runtime_put(xudc->dev); in tegra_xudc_gadget_pullup()
2076 struct tegra_xudc *xudc = to_xudc(gadget); in tegra_xudc_gadget_start() local
2083 return -EINVAL; in tegra_xudc_gadget_start()
2085 pm_runtime_get_sync(xudc->dev); in tegra_xudc_gadget_start()
2087 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_gadget_start()
2089 if (xudc->driver) { in tegra_xudc_gadget_start()
2090 ret = -EBUSY; in tegra_xudc_gadget_start()
2094 xudc->setup_state = WAIT_FOR_SETUP; in tegra_xudc_gadget_start()
2095 xudc->device_state = USB_STATE_DEFAULT; in tegra_xudc_gadget_start()
2096 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in tegra_xudc_gadget_start()
2098 ret = __tegra_xudc_ep_enable(&xudc->ep[0], &tegra_xudc_ep0_desc); in tegra_xudc_gadget_start()
2102 val = xudc_readl(xudc, CTRL); in tegra_xudc_gadget_start()
2104 xudc_writel(xudc, val, CTRL); in tegra_xudc_gadget_start()
2106 val = xudc_readl(xudc, PORTHALT); in tegra_xudc_gadget_start()
2108 xudc_writel(xudc, val, PORTHALT); in tegra_xudc_gadget_start()
2110 if (xudc->pullup) { in tegra_xudc_gadget_start()
2111 val = xudc_readl(xudc, CTRL); in tegra_xudc_gadget_start()
2113 xudc_writel(xudc, val, CTRL); in tegra_xudc_gadget_start()
2116 for (i = 0; i < xudc->soc->num_phys; i++) in tegra_xudc_gadget_start()
2117 if (xudc->usbphy[i]) in tegra_xudc_gadget_start()
2118 otg_set_peripheral(xudc->usbphy[i]->otg, gadget); in tegra_xudc_gadget_start()
2120 xudc->driver = driver; in tegra_xudc_gadget_start()
2122 dev_dbg(xudc->dev, "%s: ret value is %d", __func__, ret); in tegra_xudc_gadget_start()
2123 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_gadget_start()
2125 pm_runtime_put(xudc->dev); in tegra_xudc_gadget_start()
2132 struct tegra_xudc *xudc = to_xudc(gadget); in tegra_xudc_gadget_stop() local
2137 pm_runtime_get_sync(xudc->dev); in tegra_xudc_gadget_stop()
2139 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_gadget_stop()
2141 for (i = 0; i < xudc->soc->num_phys; i++) in tegra_xudc_gadget_stop()
2142 if (xudc->usbphy[i]) in tegra_xudc_gadget_stop()
2143 otg_set_peripheral(xudc->usbphy[i]->otg, NULL); in tegra_xudc_gadget_stop()
2145 val = xudc_readl(xudc, CTRL); in tegra_xudc_gadget_stop()
2147 xudc_writel(xudc, val, CTRL); in tegra_xudc_gadget_stop()
2149 __tegra_xudc_ep_disable(&xudc->ep[0]); in tegra_xudc_gadget_stop()
2151 xudc->driver = NULL; in tegra_xudc_gadget_stop()
2152 dev_dbg(xudc->dev, "Gadget stopped"); in tegra_xudc_gadget_stop()
2154 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_gadget_stop()
2156 pm_runtime_put(xudc->dev); in tegra_xudc_gadget_stop()
2164 struct tegra_xudc *xudc = to_xudc(gadget); in tegra_xudc_gadget_vbus_draw() local
2166 dev_dbg(xudc->dev, "%s: %u mA\n", __func__, m_a); in tegra_xudc_gadget_vbus_draw()
2168 if (xudc->curr_usbphy && xudc->curr_usbphy->chg_type == SDP_TYPE) in tegra_xudc_gadget_vbus_draw()
2169 return usb_phy_set_power(xudc->curr_usbphy, m_a); in tegra_xudc_gadget_vbus_draw()
2176 struct tegra_xudc *xudc = to_xudc(gadget); in tegra_xudc_set_selfpowered() local
2178 dev_dbg(xudc->dev, "%s: %d\n", __func__, is_on); in tegra_xudc_set_selfpowered()
2179 xudc->selfpowered = !!is_on; in tegra_xudc_set_selfpowered()
2199 tegra_xudc_ep0_queue_status(struct tegra_xudc *xudc, in tegra_xudc_ep0_queue_status() argument
2202 xudc->ep0_req->usb_req.buf = NULL; in tegra_xudc_ep0_queue_status()
2203 xudc->ep0_req->usb_req.dma = 0; in tegra_xudc_ep0_queue_status()
2204 xudc->ep0_req->usb_req.length = 0; in tegra_xudc_ep0_queue_status()
2205 xudc->ep0_req->usb_req.complete = cmpl; in tegra_xudc_ep0_queue_status()
2206 xudc->ep0_req->usb_req.context = xudc; in tegra_xudc_ep0_queue_status()
2208 return __tegra_xudc_ep_queue(&xudc->ep[0], xudc->ep0_req); in tegra_xudc_ep0_queue_status()
2212 tegra_xudc_ep0_queue_data(struct tegra_xudc *xudc, void *buf, size_t len, in tegra_xudc_ep0_queue_data() argument
2215 xudc->ep0_req->usb_req.buf = buf; in tegra_xudc_ep0_queue_data()
2216 xudc->ep0_req->usb_req.length = len; in tegra_xudc_ep0_queue_data()
2217 xudc->ep0_req->usb_req.complete = cmpl; in tegra_xudc_ep0_queue_data()
2218 xudc->ep0_req->usb_req.context = xudc; in tegra_xudc_ep0_queue_data()
2220 return __tegra_xudc_ep_queue(&xudc->ep[0], xudc->ep0_req); in tegra_xudc_ep0_queue_data()
2223 static void tegra_xudc_ep0_req_done(struct tegra_xudc *xudc) in tegra_xudc_ep0_req_done() argument
2225 switch (xudc->setup_state) { in tegra_xudc_ep0_req_done()
2227 xudc->setup_state = STATUS_STAGE_RECV; in tegra_xudc_ep0_req_done()
2228 tegra_xudc_ep0_queue_status(xudc, no_op_complete); in tegra_xudc_ep0_req_done()
2231 xudc->setup_state = STATUS_STAGE_XFER; in tegra_xudc_ep0_req_done()
2232 tegra_xudc_ep0_queue_status(xudc, no_op_complete); in tegra_xudc_ep0_req_done()
2235 xudc->setup_state = WAIT_FOR_SETUP; in tegra_xudc_ep0_req_done()
2240 static int tegra_xudc_ep0_delegate_req(struct tegra_xudc *xudc, in tegra_xudc_ep0_delegate_req() argument
2245 spin_unlock(&xudc->lock); in tegra_xudc_ep0_delegate_req()
2246 ret = xudc->driver->setup(&xudc->gadget, ctrl); in tegra_xudc_ep0_delegate_req()
2247 spin_lock(&xudc->lock); in tegra_xudc_ep0_delegate_req()
2254 struct tegra_xudc *xudc = req->context; in set_feature_complete() local
2256 if (xudc->test_mode_pattern) { in set_feature_complete()
2257 xudc_writel(xudc, xudc->test_mode_pattern, PORT_TM); in set_feature_complete()
2258 xudc->test_mode_pattern = 0; in set_feature_complete()
2262 static int tegra_xudc_ep0_set_feature(struct tegra_xudc *xudc, in tegra_xudc_ep0_set_feature() argument
2265 bool set = (ctrl->bRequest == USB_REQ_SET_FEATURE); in tegra_xudc_ep0_set_feature()
2266 u32 feature = le16_to_cpu(ctrl->wValue); in tegra_xudc_ep0_set_feature()
2267 u32 index = le16_to_cpu(ctrl->wIndex); in tegra_xudc_ep0_set_feature()
2271 if (le16_to_cpu(ctrl->wLength) != 0) in tegra_xudc_ep0_set_feature()
2272 return -EINVAL; in tegra_xudc_ep0_set_feature()
2274 switch (ctrl->bRequestType & USB_RECIP_MASK) { in tegra_xudc_ep0_set_feature()
2278 if ((xudc->gadget.speed == USB_SPEED_SUPER) || in tegra_xudc_ep0_set_feature()
2279 (xudc->device_state == USB_STATE_DEFAULT)) in tegra_xudc_ep0_set_feature()
2280 return -EINVAL; in tegra_xudc_ep0_set_feature()
2282 val = xudc_readl(xudc, PORTPM); in tegra_xudc_ep0_set_feature()
2288 xudc_writel(xudc, val, PORTPM); in tegra_xudc_ep0_set_feature()
2292 if ((xudc->device_state != USB_STATE_CONFIGURED) || in tegra_xudc_ep0_set_feature()
2293 (xudc->gadget.speed != USB_SPEED_SUPER)) in tegra_xudc_ep0_set_feature()
2294 return -EINVAL; in tegra_xudc_ep0_set_feature()
2296 val = xudc_readl(xudc, PORTPM); in tegra_xudc_ep0_set_feature()
2298 xudc->soc->u1_enable) { in tegra_xudc_ep0_set_feature()
2306 xudc->soc->u2_enable) { in tegra_xudc_ep0_set_feature()
2313 xudc_writel(xudc, val, PORTPM); in tegra_xudc_ep0_set_feature()
2316 if (xudc->gadget.speed != USB_SPEED_HIGH) in tegra_xudc_ep0_set_feature()
2317 return -EINVAL; in tegra_xudc_ep0_set_feature()
2320 return -EINVAL; in tegra_xudc_ep0_set_feature()
2322 xudc->test_mode_pattern = index >> 8; in tegra_xudc_ep0_set_feature()
2325 return -EINVAL; in tegra_xudc_ep0_set_feature()
2330 if (xudc->device_state != USB_STATE_CONFIGURED) in tegra_xudc_ep0_set_feature()
2331 return -EINVAL; in tegra_xudc_ep0_set_feature()
2336 val = xudc_readl(xudc, PORTPM); in tegra_xudc_ep0_set_feature()
2343 xudc_writel(xudc, val, PORTPM); in tegra_xudc_ep0_set_feature()
2346 return tegra_xudc_ep0_delegate_req(xudc, ctrl); in tegra_xudc_ep0_set_feature()
2348 return -EINVAL; in tegra_xudc_ep0_set_feature()
2356 if ((xudc->device_state == USB_STATE_DEFAULT) || in tegra_xudc_ep0_set_feature()
2357 ((xudc->device_state == USB_STATE_ADDRESS) && in tegra_xudc_ep0_set_feature()
2359 return -EINVAL; in tegra_xudc_ep0_set_feature()
2361 ret = __tegra_xudc_ep_set_halt(&xudc->ep[ep], set); in tegra_xudc_ep0_set_feature()
2366 return -EINVAL; in tegra_xudc_ep0_set_feature()
2369 return tegra_xudc_ep0_queue_status(xudc, set_feature_complete); in tegra_xudc_ep0_set_feature()
2372 static int tegra_xudc_ep0_get_status(struct tegra_xudc *xudc, in tegra_xudc_ep0_get_status() argument
2376 u32 val, ep, index = le16_to_cpu(ctrl->wIndex); in tegra_xudc_ep0_get_status()
2379 if (!(ctrl->bRequestType & USB_DIR_IN)) in tegra_xudc_ep0_get_status()
2380 return -EINVAL; in tegra_xudc_ep0_get_status()
2382 if ((le16_to_cpu(ctrl->wValue) != 0) || in tegra_xudc_ep0_get_status()
2383 (le16_to_cpu(ctrl->wLength) != 2)) in tegra_xudc_ep0_get_status()
2384 return -EINVAL; in tegra_xudc_ep0_get_status()
2386 switch (ctrl->bRequestType & USB_RECIP_MASK) { in tegra_xudc_ep0_get_status()
2388 val = xudc_readl(xudc, PORTPM); in tegra_xudc_ep0_get_status()
2390 if (xudc->selfpowered) in tegra_xudc_ep0_get_status()
2393 if ((xudc->gadget.speed < USB_SPEED_SUPER) && in tegra_xudc_ep0_get_status()
2397 if (xudc->gadget.speed == USB_SPEED_SUPER) { in tegra_xudc_ep0_get_status()
2405 if (xudc->gadget.speed == USB_SPEED_SUPER) { in tegra_xudc_ep0_get_status()
2407 val = xudc_readl(xudc, PORTPM); in tegra_xudc_ep0_get_status()
2415 ep_ctx = &xudc->ep_context[ep]; in tegra_xudc_ep0_get_status()
2417 if ((xudc->device_state != USB_STATE_CONFIGURED) && in tegra_xudc_ep0_get_status()
2418 ((xudc->device_state != USB_STATE_ADDRESS) || (ep != 0))) in tegra_xudc_ep0_get_status()
2419 return -EINVAL; in tegra_xudc_ep0_get_status()
2422 return -EINVAL; in tegra_xudc_ep0_get_status()
2424 if (xudc_readl(xudc, EP_HALT) & BIT(ep)) in tegra_xudc_ep0_get_status()
2428 return -EINVAL; in tegra_xudc_ep0_get_status()
2431 xudc->status_buf = cpu_to_le16(status); in tegra_xudc_ep0_get_status()
2432 return tegra_xudc_ep0_queue_data(xudc, &xudc->status_buf, in tegra_xudc_ep0_get_status()
2433 sizeof(xudc->status_buf), in tegra_xudc_ep0_get_status()
2442 static int tegra_xudc_ep0_set_sel(struct tegra_xudc *xudc, in tegra_xudc_ep0_set_sel() argument
2445 if (ctrl->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE | in tegra_xudc_ep0_set_sel()
2447 return -EINVAL; in tegra_xudc_ep0_set_sel()
2449 if (xudc->device_state == USB_STATE_DEFAULT) in tegra_xudc_ep0_set_sel()
2450 return -EINVAL; in tegra_xudc_ep0_set_sel()
2452 if ((le16_to_cpu(ctrl->wIndex) != 0) || in tegra_xudc_ep0_set_sel()
2453 (le16_to_cpu(ctrl->wValue) != 0) || in tegra_xudc_ep0_set_sel()
2454 (le16_to_cpu(ctrl->wLength) != 6)) in tegra_xudc_ep0_set_sel()
2455 return -EINVAL; in tegra_xudc_ep0_set_sel()
2457 return tegra_xudc_ep0_queue_data(xudc, &xudc->sel_timing, in tegra_xudc_ep0_set_sel()
2458 sizeof(xudc->sel_timing), in tegra_xudc_ep0_set_sel()
2467 static int tegra_xudc_ep0_set_isoch_delay(struct tegra_xudc *xudc, in tegra_xudc_ep0_set_isoch_delay() argument
2470 u32 delay = le16_to_cpu(ctrl->wValue); in tegra_xudc_ep0_set_isoch_delay()
2472 if (ctrl->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE | in tegra_xudc_ep0_set_isoch_delay()
2474 return -EINVAL; in tegra_xudc_ep0_set_isoch_delay()
2476 if ((delay > 65535) || (le16_to_cpu(ctrl->wIndex) != 0) || in tegra_xudc_ep0_set_isoch_delay()
2477 (le16_to_cpu(ctrl->wLength) != 0)) in tegra_xudc_ep0_set_isoch_delay()
2478 return -EINVAL; in tegra_xudc_ep0_set_isoch_delay()
2480 xudc->isoch_delay = delay; in tegra_xudc_ep0_set_isoch_delay()
2482 return tegra_xudc_ep0_queue_status(xudc, set_isoch_delay_complete); in tegra_xudc_ep0_set_isoch_delay()
2487 struct tegra_xudc *xudc = req->context; in set_address_complete() local
2489 if ((xudc->device_state == USB_STATE_DEFAULT) && in set_address_complete()
2490 (xudc->dev_addr != 0)) { in set_address_complete()
2491 xudc->device_state = USB_STATE_ADDRESS; in set_address_complete()
2492 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in set_address_complete()
2493 } else if ((xudc->device_state == USB_STATE_ADDRESS) && in set_address_complete()
2494 (xudc->dev_addr == 0)) { in set_address_complete()
2495 xudc->device_state = USB_STATE_DEFAULT; in set_address_complete()
2496 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in set_address_complete()
2500 static int tegra_xudc_ep0_set_address(struct tegra_xudc *xudc, in tegra_xudc_ep0_set_address() argument
2503 struct tegra_xudc_ep *ep0 = &xudc->ep[0]; in tegra_xudc_ep0_set_address()
2504 u32 val, addr = le16_to_cpu(ctrl->wValue); in tegra_xudc_ep0_set_address()
2506 if (ctrl->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE | in tegra_xudc_ep0_set_address()
2508 return -EINVAL; in tegra_xudc_ep0_set_address()
2510 if ((addr > 127) || (le16_to_cpu(ctrl->wIndex) != 0) || in tegra_xudc_ep0_set_address()
2511 (le16_to_cpu(ctrl->wLength) != 0)) in tegra_xudc_ep0_set_address()
2512 return -EINVAL; in tegra_xudc_ep0_set_address()
2514 if (xudc->device_state == USB_STATE_CONFIGURED) in tegra_xudc_ep0_set_address()
2515 return -EINVAL; in tegra_xudc_ep0_set_address()
2517 dev_dbg(xudc->dev, "set address: %u\n", addr); in tegra_xudc_ep0_set_address()
2519 xudc->dev_addr = addr; in tegra_xudc_ep0_set_address()
2520 val = xudc_readl(xudc, CTRL); in tegra_xudc_ep0_set_address()
2523 xudc_writel(xudc, val, CTRL); in tegra_xudc_ep0_set_address()
2525 ep_ctx_write_devaddr(ep0->context, addr); in tegra_xudc_ep0_set_address()
2527 return tegra_xudc_ep0_queue_status(xudc, set_address_complete); in tegra_xudc_ep0_set_address()
2530 static int tegra_xudc_ep0_standard_req(struct tegra_xudc *xudc, in tegra_xudc_ep0_standard_req() argument
2535 switch (ctrl->bRequest) { in tegra_xudc_ep0_standard_req()
2537 dev_dbg(xudc->dev, "USB_REQ_GET_STATUS\n"); in tegra_xudc_ep0_standard_req()
2538 ret = tegra_xudc_ep0_get_status(xudc, ctrl); in tegra_xudc_ep0_standard_req()
2541 dev_dbg(xudc->dev, "USB_REQ_SET_ADDRESS\n"); in tegra_xudc_ep0_standard_req()
2542 ret = tegra_xudc_ep0_set_address(xudc, ctrl); in tegra_xudc_ep0_standard_req()
2545 dev_dbg(xudc->dev, "USB_REQ_SET_SEL\n"); in tegra_xudc_ep0_standard_req()
2546 ret = tegra_xudc_ep0_set_sel(xudc, ctrl); in tegra_xudc_ep0_standard_req()
2549 dev_dbg(xudc->dev, "USB_REQ_SET_ISOCH_DELAY\n"); in tegra_xudc_ep0_standard_req()
2550 ret = tegra_xudc_ep0_set_isoch_delay(xudc, ctrl); in tegra_xudc_ep0_standard_req()
2554 dev_dbg(xudc->dev, "USB_REQ_CLEAR/SET_FEATURE\n"); in tegra_xudc_ep0_standard_req()
2555 ret = tegra_xudc_ep0_set_feature(xudc, ctrl); in tegra_xudc_ep0_standard_req()
2558 dev_dbg(xudc->dev, "USB_REQ_SET_CONFIGURATION\n"); in tegra_xudc_ep0_standard_req()
2566 ret = tegra_xudc_ep0_delegate_req(xudc, ctrl); in tegra_xudc_ep0_standard_req()
2573 static void tegra_xudc_handle_ep0_setup_packet(struct tegra_xudc *xudc, in tegra_xudc_handle_ep0_setup_packet() argument
2579 xudc->setup_seq_num = seq_num; in tegra_xudc_handle_ep0_setup_packet()
2582 ep_unhalt(xudc, 0); in tegra_xudc_handle_ep0_setup_packet()
2585 * On Tegra210, setup packets with sequence numbers 0xfffe or 0xffff in tegra_xudc_handle_ep0_setup_packet()
2588 if (xudc->soc->invalid_seq_num && in tegra_xudc_handle_ep0_setup_packet()
2590 dev_warn(xudc->dev, "invalid sequence number detected\n"); in tegra_xudc_handle_ep0_setup_packet()
2591 ep_halt(xudc, 0); in tegra_xudc_handle_ep0_setup_packet()
2595 if (ctrl->wLength) in tegra_xudc_handle_ep0_setup_packet()
2596 xudc->setup_state = (ctrl->bRequestType & USB_DIR_IN) ? in tegra_xudc_handle_ep0_setup_packet()
2599 xudc->setup_state = STATUS_STAGE_XFER; in tegra_xudc_handle_ep0_setup_packet()
2601 if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) in tegra_xudc_handle_ep0_setup_packet()
2602 ret = tegra_xudc_ep0_standard_req(xudc, ctrl); in tegra_xudc_handle_ep0_setup_packet()
2604 ret = tegra_xudc_ep0_delegate_req(xudc, ctrl); in tegra_xudc_handle_ep0_setup_packet()
2607 dev_warn(xudc->dev, "setup request failed: %d\n", ret); in tegra_xudc_handle_ep0_setup_packet()
2608 xudc->setup_state = WAIT_FOR_SETUP; in tegra_xudc_handle_ep0_setup_packet()
2609 ep_halt(xudc, 0); in tegra_xudc_handle_ep0_setup_packet()
2613 static void tegra_xudc_handle_ep0_event(struct tegra_xudc *xudc, in tegra_xudc_handle_ep0_event() argument
2619 if (xudc->setup_state != WAIT_FOR_SETUP) { in tegra_xudc_handle_ep0_event()
2626 memcpy(&xudc->setup_packet.ctrl_req, ctrl, sizeof(*ctrl)); in tegra_xudc_handle_ep0_event()
2627 xudc->setup_packet.seq_num = seq_num; in tegra_xudc_handle_ep0_event()
2628 xudc->queued_setup_packet = true; in tegra_xudc_handle_ep0_event()
2630 tegra_xudc_handle_ep0_setup_packet(xudc, ctrl, seq_num); in tegra_xudc_handle_ep0_event()
2639 list_for_each_entry(req, &ep->queue, list) { in trb_to_request()
2640 if (!req->trbs_queued) in trb_to_request()
2650 static void tegra_xudc_handle_transfer_completion(struct tegra_xudc *xudc, in tegra_xudc_handle_transfer_completion() argument
2669 (req->trbs_needed == req->trbs_queued)))) { in tegra_xudc_handle_transfer_completion()
2670 struct tegra_xudc_trb *last = req->last_trb; in tegra_xudc_handle_transfer_completion()
2674 req->usb_req.actual = req->usb_req.length - residual; in tegra_xudc_handle_transfer_completion()
2676 dev_dbg(xudc->dev, "bytes transferred %u / %u\n", in tegra_xudc_handle_transfer_completion()
2677 req->usb_req.actual, req->usb_req.length); in tegra_xudc_handle_transfer_completion()
2681 if (ep->desc && usb_endpoint_xfer_control(ep->desc)) in tegra_xudc_handle_transfer_completion()
2682 tegra_xudc_ep0_req_done(xudc); in tegra_xudc_handle_transfer_completion()
2689 ep->deq_ptr = (last - ep->transfer_ring) + 1; in tegra_xudc_handle_transfer_completion()
2690 if (ep->deq_ptr == XUDC_TRANSFER_RING_SIZE - 1) in tegra_xudc_handle_transfer_completion()
2691 ep->deq_ptr = 0; in tegra_xudc_handle_transfer_completion()
2694 dev_warn(xudc->dev, "transfer event on dequeued request\n"); in tegra_xudc_handle_transfer_completion()
2697 if (ep->desc) in tegra_xudc_handle_transfer_completion()
2701 static void tegra_xudc_handle_transfer_event(struct tegra_xudc *xudc, in tegra_xudc_handle_transfer_event() argument
2705 struct tegra_xudc_ep *ep = &xudc->ep[ep_index]; in tegra_xudc_handle_transfer_event()
2709 if (ep_ctx_read_state(ep->context) == EP_STATE_DISABLED) { in tegra_xudc_handle_transfer_event()
2710 dev_warn(xudc->dev, "transfer event on disabled EP %u\n", in tegra_xudc_handle_transfer_event()
2719 ep->deq_ptr = (trb - ep->transfer_ring) + 1; in tegra_xudc_handle_transfer_event()
2721 if (ep->deq_ptr == XUDC_TRANSFER_RING_SIZE - 1) in tegra_xudc_handle_transfer_event()
2722 ep->deq_ptr = 0; in tegra_xudc_handle_transfer_event()
2723 ep->ring_full = false; in tegra_xudc_handle_transfer_event()
2729 tegra_xudc_handle_transfer_completion(xudc, ep, event); in tegra_xudc_handle_transfer_event()
2732 dev_info(xudc->dev, "stream rejected on EP %u\n", ep_index); in tegra_xudc_handle_transfer_event()
2734 ep->stream_rejected = true; in tegra_xudc_handle_transfer_event()
2737 dev_info(xudc->dev, "prime pipe received on EP %u\n", ep_index); in tegra_xudc_handle_transfer_event()
2739 if (ep->stream_rejected) { in tegra_xudc_handle_transfer_event()
2740 ep->stream_rejected = false; in tegra_xudc_handle_transfer_event()
2744 * un-stop it. in tegra_xudc_handle_transfer_event()
2746 ep_wait_for_stopped(xudc, ep_index); in tegra_xudc_handle_transfer_event()
2755 ep_wait_for_stopped(xudc, ep_index); in tegra_xudc_handle_transfer_event()
2756 ep->enq_ptr = ep->deq_ptr; in tegra_xudc_handle_transfer_event()
2757 tegra_xudc_ep_nuke(ep, -EIO); in tegra_xudc_handle_transfer_event()
2767 dev_err(xudc->dev, "completion error %#x on EP %u\n", in tegra_xudc_handle_transfer_event()
2770 ep_halt(xudc, ep_index); in tegra_xudc_handle_transfer_event()
2773 dev_info(xudc->dev, "sequence number error\n"); in tegra_xudc_handle_transfer_event()
2779 tegra_xudc_ep_nuke(ep, -EINVAL); in tegra_xudc_handle_transfer_event()
2780 xudc->setup_state = WAIT_FOR_SETUP; in tegra_xudc_handle_transfer_event()
2781 if (!xudc->queued_setup_packet) in tegra_xudc_handle_transfer_event()
2784 tegra_xudc_handle_ep0_setup_packet(xudc, in tegra_xudc_handle_transfer_event()
2785 &xudc->setup_packet.ctrl_req, in tegra_xudc_handle_transfer_event()
2786 xudc->setup_packet.seq_num); in tegra_xudc_handle_transfer_event()
2787 xudc->queued_setup_packet = false; in tegra_xudc_handle_transfer_event()
2790 dev_dbg(xudc->dev, "stop completion code on EP %u\n", in tegra_xudc_handle_transfer_event()
2794 tegra_xudc_ep_nuke(ep, -ECONNREFUSED); in tegra_xudc_handle_transfer_event()
2797 dev_dbg(xudc->dev, "completion event %#x on EP %u\n", in tegra_xudc_handle_transfer_event()
2803 static void tegra_xudc_reset(struct tegra_xudc *xudc) in tegra_xudc_reset() argument
2805 struct tegra_xudc_ep *ep0 = &xudc->ep[0]; in tegra_xudc_reset()
2809 xudc->setup_state = WAIT_FOR_SETUP; in tegra_xudc_reset()
2810 xudc->device_state = USB_STATE_DEFAULT; in tegra_xudc_reset()
2811 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in tegra_xudc_reset()
2813 ep_unpause_all(xudc); in tegra_xudc_reset()
2815 for (i = 0; i < ARRAY_SIZE(xudc->ep); i++) in tegra_xudc_reset()
2816 tegra_xudc_ep_nuke(&xudc->ep[i], -ESHUTDOWN); in tegra_xudc_reset()
2822 ep0->deq_ptr = ep0->enq_ptr; in tegra_xudc_reset()
2823 ep0->ring_full = false; in tegra_xudc_reset()
2825 xudc->setup_seq_num = 0; in tegra_xudc_reset()
2826 xudc->queued_setup_packet = false; in tegra_xudc_reset()
2828 ep_ctx_write_rsvd(ep0->context, 0); in tegra_xudc_reset()
2829 ep_ctx_write_partial_td(ep0->context, 0); in tegra_xudc_reset()
2830 ep_ctx_write_splitxstate(ep0->context, 0); in tegra_xudc_reset()
2831 ep_ctx_write_seq_num(ep0->context, 0); in tegra_xudc_reset()
2833 deq_ptr = trb_virt_to_phys(ep0, &ep0->transfer_ring[ep0->deq_ptr]); in tegra_xudc_reset()
2835 if (!dma_mapping_error(xudc->dev, deq_ptr)) { in tegra_xudc_reset()
2836 ep_ctx_write_deq_ptr(ep0->context, deq_ptr); in tegra_xudc_reset()
2837 ep_ctx_write_dcs(ep0->context, ep0->pcs); in tegra_xudc_reset()
2840 ep_unhalt_all(xudc); in tegra_xudc_reset()
2841 ep_reload(xudc, 0); in tegra_xudc_reset()
2842 ep_unpause(xudc, 0); in tegra_xudc_reset()
2845 static void tegra_xudc_port_connect(struct tegra_xudc *xudc) in tegra_xudc_port_connect() argument
2847 struct tegra_xudc_ep *ep0 = &xudc->ep[0]; in tegra_xudc_port_connect()
2851 val = (xudc_readl(xudc, PORTSC) & PORTSC_PS_MASK) >> PORTSC_PS_SHIFT; in tegra_xudc_port_connect()
2854 xudc->gadget.speed = USB_SPEED_LOW; in tegra_xudc_port_connect()
2857 xudc->gadget.speed = USB_SPEED_FULL; in tegra_xudc_port_connect()
2860 xudc->gadget.speed = USB_SPEED_HIGH; in tegra_xudc_port_connect()
2863 xudc->gadget.speed = USB_SPEED_SUPER; in tegra_xudc_port_connect()
2866 xudc->gadget.speed = USB_SPEED_UNKNOWN; in tegra_xudc_port_connect()
2870 xudc->device_state = USB_STATE_DEFAULT; in tegra_xudc_port_connect()
2871 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in tegra_xudc_port_connect()
2873 xudc->setup_state = WAIT_FOR_SETUP; in tegra_xudc_port_connect()
2875 if (xudc->gadget.speed == USB_SPEED_SUPER) in tegra_xudc_port_connect()
2880 ep_ctx_write_max_packet_size(ep0->context, maxpacket); in tegra_xudc_port_connect()
2882 usb_ep_set_maxpacket_limit(&ep0->usb_ep, maxpacket); in tegra_xudc_port_connect()
2884 if (!xudc->soc->u1_enable) { in tegra_xudc_port_connect()
2885 val = xudc_readl(xudc, PORTPM); in tegra_xudc_port_connect()
2887 xudc_writel(xudc, val, PORTPM); in tegra_xudc_port_connect()
2890 if (!xudc->soc->u2_enable) { in tegra_xudc_port_connect()
2891 val = xudc_readl(xudc, PORTPM); in tegra_xudc_port_connect()
2893 xudc_writel(xudc, val, PORTPM); in tegra_xudc_port_connect()
2896 if (xudc->gadget.speed <= USB_SPEED_HIGH) { in tegra_xudc_port_connect()
2897 val = xudc_readl(xudc, PORTPM); in tegra_xudc_port_connect()
2899 if (xudc->soc->lpm_enable) in tegra_xudc_port_connect()
2903 xudc_writel(xudc, val, PORTPM); in tegra_xudc_port_connect()
2906 val = xudc_readl(xudc, ST); in tegra_xudc_port_connect()
2908 xudc_writel(xudc, ST_RC, ST); in tegra_xudc_port_connect()
2911 static void tegra_xudc_port_disconnect(struct tegra_xudc *xudc) in tegra_xudc_port_disconnect() argument
2913 tegra_xudc_reset(xudc); in tegra_xudc_port_disconnect()
2915 if (xudc->driver && xudc->driver->disconnect) { in tegra_xudc_port_disconnect()
2916 spin_unlock(&xudc->lock); in tegra_xudc_port_disconnect()
2917 xudc->driver->disconnect(&xudc->gadget); in tegra_xudc_port_disconnect()
2918 spin_lock(&xudc->lock); in tegra_xudc_port_disconnect()
2921 xudc->device_state = USB_STATE_NOTATTACHED; in tegra_xudc_port_disconnect()
2922 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in tegra_xudc_port_disconnect()
2924 complete(&xudc->disconnect_complete); in tegra_xudc_port_disconnect()
2927 static void tegra_xudc_port_reset(struct tegra_xudc *xudc) in tegra_xudc_port_reset() argument
2929 tegra_xudc_reset(xudc); in tegra_xudc_port_reset()
2931 if (xudc->driver) { in tegra_xudc_port_reset()
2932 spin_unlock(&xudc->lock); in tegra_xudc_port_reset()
2933 usb_gadget_udc_reset(&xudc->gadget, xudc->driver); in tegra_xudc_port_reset()
2934 spin_lock(&xudc->lock); in tegra_xudc_port_reset()
2937 tegra_xudc_port_connect(xudc); in tegra_xudc_port_reset()
2940 static void tegra_xudc_port_suspend(struct tegra_xudc *xudc) in tegra_xudc_port_suspend() argument
2942 dev_dbg(xudc->dev, "port suspend\n"); in tegra_xudc_port_suspend()
2944 xudc->resume_state = xudc->device_state; in tegra_xudc_port_suspend()
2945 xudc->device_state = USB_STATE_SUSPENDED; in tegra_xudc_port_suspend()
2946 usb_gadget_set_state(&xudc->gadget, xudc->device_state); in tegra_xudc_port_suspend()
2948 if (xudc->driver->suspend) { in tegra_xudc_port_suspend()
2949 spin_unlock(&xudc->lock); in tegra_xudc_port_suspend()
2950 xudc->driver->suspend(&xudc->gadget); in tegra_xudc_port_suspend()
2951 spin_lock(&xudc->lock); in tegra_xudc_port_suspend()
2955 static void tegra_xudc_port_resume(struct tegra_xudc *xudc) in tegra_xudc_port_resume() argument
2957 dev_dbg(xudc->dev, "port resume\n"); in tegra_xudc_port_resume()
2959 tegra_xudc_resume_device_state(xudc); in tegra_xudc_port_resume()
2961 if (xudc->driver->resume) { in tegra_xudc_port_resume()
2962 spin_unlock(&xudc->lock); in tegra_xudc_port_resume()
2963 xudc->driver->resume(&xudc->gadget); in tegra_xudc_port_resume()
2964 spin_lock(&xudc->lock); in tegra_xudc_port_resume()
2968 static inline void clear_port_change(struct tegra_xudc *xudc, u32 flag) in clear_port_change() argument
2972 val = xudc_readl(xudc, PORTSC); in clear_port_change()
2975 xudc_writel(xudc, val, PORTSC); in clear_port_change()
2978 static void __tegra_xudc_handle_port_status(struct tegra_xudc *xudc) in __tegra_xudc_handle_port_status() argument
2982 porthalt = xudc_readl(xudc, PORTHALT); in __tegra_xudc_handle_port_status()
2985 dev_dbg(xudc->dev, "STCHG_REQ, PORTHALT = %#x\n", porthalt); in __tegra_xudc_handle_port_status()
2987 xudc_writel(xudc, porthalt, PORTHALT); in __tegra_xudc_handle_port_status()
2990 portsc = xudc_readl(xudc, PORTSC); in __tegra_xudc_handle_port_status()
2992 dev_dbg(xudc->dev, "PRC, PR, PORTSC = %#x\n", portsc); in __tegra_xudc_handle_port_status()
2993 clear_port_change(xudc, PORTSC_PRC | PORTSC_PED); in __tegra_xudc_handle_port_status()
2995 if (xudc->soc->port_reset_quirk) { in __tegra_xudc_handle_port_status()
2996 schedule_delayed_work(&xudc->port_reset_war_work, in __tegra_xudc_handle_port_status()
2998 xudc->wait_for_sec_prc = 1; in __tegra_xudc_handle_port_status()
3003 dev_dbg(xudc->dev, "PRC, Not PR, PORTSC = %#x\n", portsc); in __tegra_xudc_handle_port_status()
3004 clear_port_change(xudc, PORTSC_PRC | PORTSC_PED); in __tegra_xudc_handle_port_status()
3005 tegra_xudc_port_reset(xudc); in __tegra_xudc_handle_port_status()
3006 cancel_delayed_work(&xudc->port_reset_war_work); in __tegra_xudc_handle_port_status()
3007 xudc->wait_for_sec_prc = 0; in __tegra_xudc_handle_port_status()
3010 portsc = xudc_readl(xudc, PORTSC); in __tegra_xudc_handle_port_status()
3012 dev_dbg(xudc->dev, "WRC, PORTSC = %#x\n", portsc); in __tegra_xudc_handle_port_status()
3013 clear_port_change(xudc, PORTSC_WRC | PORTSC_PED); in __tegra_xudc_handle_port_status()
3014 if (!(xudc_readl(xudc, PORTSC) & PORTSC_WPR)) in __tegra_xudc_handle_port_status()
3015 tegra_xudc_port_reset(xudc); in __tegra_xudc_handle_port_status()
3018 portsc = xudc_readl(xudc, PORTSC); in __tegra_xudc_handle_port_status()
3020 dev_dbg(xudc->dev, "CSC, PORTSC = %#x\n", portsc); in __tegra_xudc_handle_port_status()
3021 clear_port_change(xudc, PORTSC_CSC); in __tegra_xudc_handle_port_status()
3024 tegra_xudc_port_connect(xudc); in __tegra_xudc_handle_port_status()
3026 tegra_xudc_port_disconnect(xudc); in __tegra_xudc_handle_port_status()
3028 if (xudc->wait_csc) { in __tegra_xudc_handle_port_status()
3029 cancel_delayed_work(&xudc->plc_reset_work); in __tegra_xudc_handle_port_status()
3030 xudc->wait_csc = false; in __tegra_xudc_handle_port_status()
3034 portsc = xudc_readl(xudc, PORTSC); in __tegra_xudc_handle_port_status()
3038 dev_dbg(xudc->dev, "PLC, PORTSC = %#x\n", portsc); in __tegra_xudc_handle_port_status()
3039 clear_port_change(xudc, PORTSC_PLC); in __tegra_xudc_handle_port_status()
3042 tegra_xudc_port_suspend(xudc); in __tegra_xudc_handle_port_status()
3045 if (xudc->gadget.speed < USB_SPEED_SUPER) in __tegra_xudc_handle_port_status()
3046 tegra_xudc_port_resume(xudc); in __tegra_xudc_handle_port_status()
3049 if (xudc->gadget.speed == USB_SPEED_SUPER) in __tegra_xudc_handle_port_status()
3050 tegra_xudc_port_resume(xudc); in __tegra_xudc_handle_port_status()
3053 schedule_delayed_work(&xudc->plc_reset_work, in __tegra_xudc_handle_port_status()
3055 xudc->wait_csc = true; in __tegra_xudc_handle_port_status()
3063 dev_warn(xudc->dev, "CEC, PORTSC = %#x\n", portsc); in __tegra_xudc_handle_port_status()
3064 clear_port_change(xudc, PORTSC_CEC); in __tegra_xudc_handle_port_status()
3067 dev_dbg(xudc->dev, "PORTSC = %#x\n", xudc_readl(xudc, PORTSC)); in __tegra_xudc_handle_port_status()
3070 static void tegra_xudc_handle_port_status(struct tegra_xudc *xudc) in tegra_xudc_handle_port_status() argument
3072 while ((xudc_readl(xudc, PORTSC) & PORTSC_CHANGE_MASK) || in tegra_xudc_handle_port_status()
3073 (xudc_readl(xudc, PORTHALT) & PORTHALT_STCHG_REQ)) in tegra_xudc_handle_port_status()
3074 __tegra_xudc_handle_port_status(xudc); in tegra_xudc_handle_port_status()
3077 static void tegra_xudc_handle_event(struct tegra_xudc *xudc, in tegra_xudc_handle_event() argument
3082 dump_trb(xudc, "EVENT", event); in tegra_xudc_handle_event()
3086 tegra_xudc_handle_port_status(xudc); in tegra_xudc_handle_event()
3089 tegra_xudc_handle_transfer_event(xudc, event); in tegra_xudc_handle_event()
3092 tegra_xudc_handle_ep0_event(xudc, event); in tegra_xudc_handle_event()
3095 dev_info(xudc->dev, "Unrecognized TRB type = %#x\n", type); in tegra_xudc_handle_event()
3100 static void tegra_xudc_process_event_ring(struct tegra_xudc *xudc) in tegra_xudc_process_event_ring() argument
3106 event = xudc->event_ring[xudc->event_ring_index] + in tegra_xudc_process_event_ring()
3107 xudc->event_ring_deq_ptr; in tegra_xudc_process_event_ring()
3109 if (trb_read_cycle(event) != xudc->ccs) in tegra_xudc_process_event_ring()
3112 tegra_xudc_handle_event(xudc, event); in tegra_xudc_process_event_ring()
3114 xudc->event_ring_deq_ptr++; in tegra_xudc_process_event_ring()
3115 if (xudc->event_ring_deq_ptr == XUDC_EVENT_RING_SIZE) { in tegra_xudc_process_event_ring()
3116 xudc->event_ring_deq_ptr = 0; in tegra_xudc_process_event_ring()
3117 xudc->event_ring_index++; in tegra_xudc_process_event_ring()
3120 if (xudc->event_ring_index == XUDC_NR_EVENT_RINGS) { in tegra_xudc_process_event_ring()
3121 xudc->event_ring_index = 0; in tegra_xudc_process_event_ring()
3122 xudc->ccs = !xudc->ccs; in tegra_xudc_process_event_ring()
3126 erdp = xudc->event_ring_phys[xudc->event_ring_index] + in tegra_xudc_process_event_ring()
3127 xudc->event_ring_deq_ptr * sizeof(*event); in tegra_xudc_process_event_ring()
3129 xudc_writel(xudc, upper_32_bits(erdp), ERDPHI); in tegra_xudc_process_event_ring()
3130 xudc_writel(xudc, lower_32_bits(erdp) | ERDPLO_EHB, ERDPLO); in tegra_xudc_process_event_ring()
3135 struct tegra_xudc *xudc = data; in tegra_xudc_irq() local
3139 val = xudc_readl(xudc, ST); in tegra_xudc_irq()
3142 xudc_writel(xudc, ST_IP, ST); in tegra_xudc_irq()
3144 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_irq()
3145 tegra_xudc_process_event_ring(xudc); in tegra_xudc_irq()
3146 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_irq()
3151 static int tegra_xudc_alloc_ep(struct tegra_xudc *xudc, unsigned int index) in tegra_xudc_alloc_ep() argument
3153 struct tegra_xudc_ep *ep = &xudc->ep[index]; in tegra_xudc_alloc_ep()
3155 ep->xudc = xudc; in tegra_xudc_alloc_ep()
3156 ep->index = index; in tegra_xudc_alloc_ep()
3157 ep->context = &xudc->ep_context[index]; in tegra_xudc_alloc_ep()
3158 INIT_LIST_HEAD(&ep->queue); in tegra_xudc_alloc_ep()
3162 * EP0 is bi-directional, EP1 is unused. in tegra_xudc_alloc_ep()
3167 ep->transfer_ring = dma_pool_alloc(xudc->transfer_ring_pool, in tegra_xudc_alloc_ep()
3169 &ep->transfer_ring_phys); in tegra_xudc_alloc_ep()
3170 if (!ep->transfer_ring) in tegra_xudc_alloc_ep()
3171 return -ENOMEM; in tegra_xudc_alloc_ep()
3174 snprintf(ep->name, sizeof(ep->name), "ep%u%s", index / 2, in tegra_xudc_alloc_ep()
3176 ep->usb_ep.name = ep->name; in tegra_xudc_alloc_ep()
3177 usb_ep_set_maxpacket_limit(&ep->usb_ep, 1024); in tegra_xudc_alloc_ep()
3178 ep->usb_ep.max_streams = 16; in tegra_xudc_alloc_ep()
3179 ep->usb_ep.ops = &tegra_xudc_ep_ops; in tegra_xudc_alloc_ep()
3180 ep->usb_ep.caps.type_bulk = true; in tegra_xudc_alloc_ep()
3181 ep->usb_ep.caps.type_int = true; in tegra_xudc_alloc_ep()
3183 ep->usb_ep.caps.dir_in = true; in tegra_xudc_alloc_ep()
3185 ep->usb_ep.caps.dir_out = true; in tegra_xudc_alloc_ep()
3186 list_add_tail(&ep->usb_ep.ep_list, &xudc->gadget.ep_list); in tegra_xudc_alloc_ep()
3188 strscpy(ep->name, "ep0", 3); in tegra_xudc_alloc_ep()
3189 ep->usb_ep.name = ep->name; in tegra_xudc_alloc_ep()
3190 usb_ep_set_maxpacket_limit(&ep->usb_ep, 512); in tegra_xudc_alloc_ep()
3191 ep->usb_ep.ops = &tegra_xudc_ep0_ops; in tegra_xudc_alloc_ep()
3192 ep->usb_ep.caps.type_control = true; in tegra_xudc_alloc_ep()
3193 ep->usb_ep.caps.dir_in = true; in tegra_xudc_alloc_ep()
3194 ep->usb_ep.caps.dir_out = true; in tegra_xudc_alloc_ep()
3200 static void tegra_xudc_free_ep(struct tegra_xudc *xudc, unsigned int index) in tegra_xudc_free_ep() argument
3202 struct tegra_xudc_ep *ep = &xudc->ep[index]; in tegra_xudc_free_ep()
3206 * EP0 is bi-directional, EP1 is unused. in tegra_xudc_free_ep()
3211 dma_pool_free(xudc->transfer_ring_pool, ep->transfer_ring, in tegra_xudc_free_ep()
3212 ep->transfer_ring_phys); in tegra_xudc_free_ep()
3215 static int tegra_xudc_alloc_eps(struct tegra_xudc *xudc) in tegra_xudc_alloc_eps() argument
3221 xudc->ep_context = in tegra_xudc_alloc_eps()
3222 dma_alloc_coherent(xudc->dev, XUDC_NR_EPS * in tegra_xudc_alloc_eps()
3223 sizeof(*xudc->ep_context), in tegra_xudc_alloc_eps()
3224 &xudc->ep_context_phys, GFP_KERNEL); in tegra_xudc_alloc_eps()
3225 if (!xudc->ep_context) in tegra_xudc_alloc_eps()
3226 return -ENOMEM; in tegra_xudc_alloc_eps()
3228 xudc->transfer_ring_pool = in tegra_xudc_alloc_eps()
3229 dmam_pool_create(dev_name(xudc->dev), xudc->dev, in tegra_xudc_alloc_eps()
3233 if (!xudc->transfer_ring_pool) { in tegra_xudc_alloc_eps()
3234 err = -ENOMEM; in tegra_xudc_alloc_eps()
3238 INIT_LIST_HEAD(&xudc->gadget.ep_list); in tegra_xudc_alloc_eps()
3239 for (i = 0; i < ARRAY_SIZE(xudc->ep); i++) { in tegra_xudc_alloc_eps()
3240 err = tegra_xudc_alloc_ep(xudc, i); in tegra_xudc_alloc_eps()
3245 req = tegra_xudc_ep_alloc_request(&xudc->ep[0].usb_ep, GFP_KERNEL); in tegra_xudc_alloc_eps()
3247 err = -ENOMEM; in tegra_xudc_alloc_eps()
3250 xudc->ep0_req = to_xudc_req(req); in tegra_xudc_alloc_eps()
3255 for (; i > 0; i--) in tegra_xudc_alloc_eps()
3256 tegra_xudc_free_ep(xudc, i - 1); in tegra_xudc_alloc_eps()
3258 dma_free_coherent(xudc->dev, XUDC_NR_EPS * sizeof(*xudc->ep_context), in tegra_xudc_alloc_eps()
3259 xudc->ep_context, xudc->ep_context_phys); in tegra_xudc_alloc_eps()
3263 static void tegra_xudc_init_eps(struct tegra_xudc *xudc) in tegra_xudc_init_eps() argument
3265 xudc_writel(xudc, lower_32_bits(xudc->ep_context_phys), ECPLO); in tegra_xudc_init_eps()
3266 xudc_writel(xudc, upper_32_bits(xudc->ep_context_phys), ECPHI); in tegra_xudc_init_eps()
3269 static void tegra_xudc_free_eps(struct tegra_xudc *xudc) in tegra_xudc_free_eps() argument
3273 tegra_xudc_ep_free_request(&xudc->ep[0].usb_ep, in tegra_xudc_free_eps()
3274 &xudc->ep0_req->usb_req); in tegra_xudc_free_eps()
3276 for (i = 0; i < ARRAY_SIZE(xudc->ep); i++) in tegra_xudc_free_eps()
3277 tegra_xudc_free_ep(xudc, i); in tegra_xudc_free_eps()
3279 dma_free_coherent(xudc->dev, XUDC_NR_EPS * sizeof(*xudc->ep_context), in tegra_xudc_free_eps()
3280 xudc->ep_context, xudc->ep_context_phys); in tegra_xudc_free_eps()
3283 static int tegra_xudc_alloc_event_ring(struct tegra_xudc *xudc) in tegra_xudc_alloc_event_ring() argument
3287 for (i = 0; i < ARRAY_SIZE(xudc->event_ring); i++) { in tegra_xudc_alloc_event_ring()
3288 xudc->event_ring[i] = in tegra_xudc_alloc_event_ring()
3289 dma_alloc_coherent(xudc->dev, XUDC_EVENT_RING_SIZE * in tegra_xudc_alloc_event_ring()
3290 sizeof(*xudc->event_ring[i]), in tegra_xudc_alloc_event_ring()
3291 &xudc->event_ring_phys[i], in tegra_xudc_alloc_event_ring()
3293 if (!xudc->event_ring[i]) in tegra_xudc_alloc_event_ring()
3300 for (; i > 0; i--) { in tegra_xudc_alloc_event_ring()
3301 dma_free_coherent(xudc->dev, XUDC_EVENT_RING_SIZE * in tegra_xudc_alloc_event_ring()
3302 sizeof(*xudc->event_ring[i - 1]), in tegra_xudc_alloc_event_ring()
3303 xudc->event_ring[i - 1], in tegra_xudc_alloc_event_ring()
3304 xudc->event_ring_phys[i - 1]); in tegra_xudc_alloc_event_ring()
3306 return -ENOMEM; in tegra_xudc_alloc_event_ring()
3309 static void tegra_xudc_init_event_ring(struct tegra_xudc *xudc) in tegra_xudc_init_event_ring() argument
3314 for (i = 0; i < ARRAY_SIZE(xudc->event_ring); i++) { in tegra_xudc_init_event_ring()
3315 memset(xudc->event_ring[i], 0, XUDC_EVENT_RING_SIZE * in tegra_xudc_init_event_ring()
3316 sizeof(*xudc->event_ring[i])); in tegra_xudc_init_event_ring()
3318 val = xudc_readl(xudc, ERSTSZ); in tegra_xudc_init_event_ring()
3321 xudc_writel(xudc, val, ERSTSZ); in tegra_xudc_init_event_ring()
3323 xudc_writel(xudc, lower_32_bits(xudc->event_ring_phys[i]), in tegra_xudc_init_event_ring()
3325 xudc_writel(xudc, upper_32_bits(xudc->event_ring_phys[i]), in tegra_xudc_init_event_ring()
3329 val = lower_32_bits(xudc->event_ring_phys[0]); in tegra_xudc_init_event_ring()
3330 xudc_writel(xudc, val, ERDPLO); in tegra_xudc_init_event_ring()
3332 xudc_writel(xudc, val, EREPLO); in tegra_xudc_init_event_ring()
3334 val = upper_32_bits(xudc->event_ring_phys[0]); in tegra_xudc_init_event_ring()
3335 xudc_writel(xudc, val, ERDPHI); in tegra_xudc_init_event_ring()
3336 xudc_writel(xudc, val, EREPHI); in tegra_xudc_init_event_ring()
3338 xudc->ccs = true; in tegra_xudc_init_event_ring()
3339 xudc->event_ring_index = 0; in tegra_xudc_init_event_ring()
3340 xudc->event_ring_deq_ptr = 0; in tegra_xudc_init_event_ring()
3343 static void tegra_xudc_free_event_ring(struct tegra_xudc *xudc) in tegra_xudc_free_event_ring() argument
3347 for (i = 0; i < ARRAY_SIZE(xudc->event_ring); i++) { in tegra_xudc_free_event_ring()
3348 dma_free_coherent(xudc->dev, XUDC_EVENT_RING_SIZE * in tegra_xudc_free_event_ring()
3349 sizeof(*xudc->event_ring[i]), in tegra_xudc_free_event_ring()
3350 xudc->event_ring[i], in tegra_xudc_free_event_ring()
3351 xudc->event_ring_phys[i]); in tegra_xudc_free_event_ring()
3355 static void tegra_xudc_fpci_ipfs_init(struct tegra_xudc *xudc) in tegra_xudc_fpci_ipfs_init() argument
3359 if (xudc->soc->has_ipfs) { in tegra_xudc_fpci_ipfs_init()
3360 val = ipfs_readl(xudc, XUSB_DEV_CONFIGURATION_0); in tegra_xudc_fpci_ipfs_init()
3362 ipfs_writel(xudc, val, XUSB_DEV_CONFIGURATION_0); in tegra_xudc_fpci_ipfs_init()
3369 fpci_writel(xudc, val, XUSB_DEV_CFG_1); in tegra_xudc_fpci_ipfs_init()
3372 val = fpci_readl(xudc, XUSB_DEV_CFG_4); in tegra_xudc_fpci_ipfs_init()
3374 val |= xudc->phys_base & (XUSB_DEV_CFG_4_BASE_ADDR_MASK); in tegra_xudc_fpci_ipfs_init()
3376 fpci_writel(xudc, val, XUSB_DEV_CFG_4); in tegra_xudc_fpci_ipfs_init()
3377 fpci_writel(xudc, upper_32_bits(xudc->phys_base), XUSB_DEV_CFG_5); in tegra_xudc_fpci_ipfs_init()
3381 if (xudc->soc->has_ipfs) { in tegra_xudc_fpci_ipfs_init()
3383 val = ipfs_readl(xudc, XUSB_DEV_INTR_MASK_0); in tegra_xudc_fpci_ipfs_init()
3385 ipfs_writel(xudc, val, XUSB_DEV_INTR_MASK_0); in tegra_xudc_fpci_ipfs_init()
3389 static void tegra_xudc_device_params_init(struct tegra_xudc *xudc) in tegra_xudc_device_params_init() argument
3393 if (xudc->soc->has_ipfs) { in tegra_xudc_device_params_init()
3394 val = xudc_readl(xudc, BLCG); in tegra_xudc_device_params_init()
3402 xudc_writel(xudc, val, BLCG); in tegra_xudc_device_params_init()
3405 if (xudc->soc->port_speed_quirk) in tegra_xudc_device_params_init()
3406 tegra_xudc_limit_port_speed(xudc); in tegra_xudc_device_params_init()
3409 val = xudc_readl(xudc, SSPX_CORE_PADCTL4); in tegra_xudc_device_params_init()
3412 xudc_writel(xudc, val, SSPX_CORE_PADCTL4); in tegra_xudc_device_params_init()
3415 val = xudc_readl(xudc, SSPX_CORE_CNT0); in tegra_xudc_device_params_init()
3418 xudc_writel(xudc, val, SSPX_CORE_CNT0); in tegra_xudc_device_params_init()
3421 val = xudc_readl(xudc, SSPX_CORE_CNT30); in tegra_xudc_device_params_init()
3424 xudc_writel(xudc, val, SSPX_CORE_CNT30); in tegra_xudc_device_params_init()
3426 if (xudc->soc->lpm_enable) { in tegra_xudc_device_params_init()
3428 val = xudc_readl(xudc, HSFSPI_COUNT13); in tegra_xudc_device_params_init()
3431 xudc_writel(xudc, val, HSFSPI_COUNT13); in tegra_xudc_device_params_init()
3438 val = xudc_readl(xudc, SSPX_CORE_CNT32); in tegra_xudc_device_params_init()
3441 xudc_writel(xudc, val, SSPX_CORE_CNT32); in tegra_xudc_device_params_init()
3444 val = xudc_readl(xudc, CFG_DEV_FE); in tegra_xudc_device_params_init()
3447 xudc_writel(xudc, val, CFG_DEV_FE); in tegra_xudc_device_params_init()
3449 val = xudc_readl(xudc, PORTSC); in tegra_xudc_device_params_init()
3452 xudc_writel(xudc, val, PORTSC); in tegra_xudc_device_params_init()
3455 val = xudc_readl(xudc, CFG_DEV_FE); in tegra_xudc_device_params_init()
3458 xudc_writel(xudc, val, CFG_DEV_FE); in tegra_xudc_device_params_init()
3460 val = xudc_readl(xudc, PORTSC); in tegra_xudc_device_params_init()
3463 xudc_writel(xudc, val, PORTSC); in tegra_xudc_device_params_init()
3466 val = xudc_readl(xudc, CFG_DEV_FE); in tegra_xudc_device_params_init()
3468 xudc_writel(xudc, val, CFG_DEV_FE); in tegra_xudc_device_params_init()
3474 val = xudc_readl(xudc, CFG_DEV_FE); in tegra_xudc_device_params_init()
3476 xudc_writel(xudc, val, CFG_DEV_FE); in tegra_xudc_device_params_init()
3480 val = xudc_readl(xudc, RT_IMOD); in tegra_xudc_device_params_init()
3483 xudc_writel(xudc, val, RT_IMOD); in tegra_xudc_device_params_init()
3486 val = xudc_readl(xudc, CFG_DEV_SSPI_XFER); in tegra_xudc_device_params_init()
3489 xudc_writel(xudc, val, CFG_DEV_SSPI_XFER); in tegra_xudc_device_params_init()
3492 static int tegra_xudc_phy_get(struct tegra_xudc *xudc) in tegra_xudc_phy_get() argument
3497 xudc->utmi_phy = devm_kcalloc(xudc->dev, xudc->soc->num_phys, in tegra_xudc_phy_get()
3498 sizeof(*xudc->utmi_phy), GFP_KERNEL); in tegra_xudc_phy_get()
3499 if (!xudc->utmi_phy) in tegra_xudc_phy_get()
3500 return -ENOMEM; in tegra_xudc_phy_get()
3502 xudc->usb3_phy = devm_kcalloc(xudc->dev, xudc->soc->num_phys, in tegra_xudc_phy_get()
3503 sizeof(*xudc->usb3_phy), GFP_KERNEL); in tegra_xudc_phy_get()
3504 if (!xudc->usb3_phy) in tegra_xudc_phy_get()
3505 return -ENOMEM; in tegra_xudc_phy_get()
3507 xudc->usbphy = devm_kcalloc(xudc->dev, xudc->soc->num_phys, in tegra_xudc_phy_get()
3508 sizeof(*xudc->usbphy), GFP_KERNEL); in tegra_xudc_phy_get()
3509 if (!xudc->usbphy) in tegra_xudc_phy_get()
3510 return -ENOMEM; in tegra_xudc_phy_get()
3512 xudc->vbus_nb.notifier_call = tegra_xudc_vbus_notify; in tegra_xudc_phy_get()
3514 for (i = 0; i < xudc->soc->num_phys; i++) { in tegra_xudc_phy_get()
3515 char phy_name[] = "usb.-."; in tegra_xudc_phy_get()
3518 snprintf(phy_name, sizeof(phy_name), "usb2-%d", i); in tegra_xudc_phy_get()
3519 xudc->utmi_phy[i] = devm_phy_optional_get(xudc->dev, phy_name); in tegra_xudc_phy_get()
3520 if (IS_ERR(xudc->utmi_phy[i])) { in tegra_xudc_phy_get()
3521 err = PTR_ERR(xudc->utmi_phy[i]); in tegra_xudc_phy_get()
3522 dev_err_probe(xudc->dev, err, in tegra_xudc_phy_get()
3523 "failed to get PHY for phy-name usb2-%d\n", i); in tegra_xudc_phy_get()
3525 } else if (xudc->utmi_phy[i]) { in tegra_xudc_phy_get()
3526 /* Get usb-phy, if utmi phy is available */ in tegra_xudc_phy_get()
3527 xudc->usbphy[i] = devm_usb_get_phy_by_node(xudc->dev, in tegra_xudc_phy_get()
3528 xudc->utmi_phy[i]->dev.of_node, in tegra_xudc_phy_get()
3530 if (IS_ERR(xudc->usbphy[i])) { in tegra_xudc_phy_get()
3531 err = PTR_ERR(xudc->usbphy[i]); in tegra_xudc_phy_get()
3532 dev_err_probe(xudc->dev, err, in tegra_xudc_phy_get()
3533 "failed to get usbphy-%d\n", i); in tegra_xudc_phy_get()
3536 } else if (!xudc->utmi_phy[i]) { in tegra_xudc_phy_get()
3542 usb3_companion_port = tegra_xusb_padctl_get_usb3_companion(xudc->padctl, i); in tegra_xudc_phy_get()
3546 for (j = 0; j < xudc->soc->num_phys; j++) { in tegra_xudc_phy_get()
3547 snprintf(phy_name, sizeof(phy_name), "usb3-%d", j); in tegra_xudc_phy_get()
3548 xudc->usb3_phy[i] = devm_phy_optional_get(xudc->dev, phy_name); in tegra_xudc_phy_get()
3549 if (IS_ERR(xudc->usb3_phy[i])) { in tegra_xudc_phy_get()
3550 err = PTR_ERR(xudc->usb3_phy[i]); in tegra_xudc_phy_get()
3551 dev_err_probe(xudc->dev, err, in tegra_xudc_phy_get()
3552 "failed to get PHY for phy-name usb3-%d\n", j); in tegra_xudc_phy_get()
3554 } else if (xudc->usb3_phy[i]) { in tegra_xudc_phy_get()
3556 tegra_xusb_padctl_get_port_number(xudc->utmi_phy[i]); in tegra_xudc_phy_get()
3558 tegra_xusb_padctl_get_port_number(xudc->usb3_phy[i]); in tegra_xudc_phy_get()
3560 dev_dbg(xudc->dev, "USB2 port %d is paired with USB3 port %d for device mode port %d\n", in tegra_xudc_phy_get()
3571 for (i = 0; i < xudc->soc->num_phys; i++) { in tegra_xudc_phy_get()
3572 xudc->usb3_phy[i] = NULL; in tegra_xudc_phy_get()
3573 xudc->utmi_phy[i] = NULL; in tegra_xudc_phy_get()
3574 xudc->usbphy[i] = NULL; in tegra_xudc_phy_get()
3580 static void tegra_xudc_phy_exit(struct tegra_xudc *xudc) in tegra_xudc_phy_exit() argument
3584 for (i = 0; i < xudc->soc->num_phys; i++) { in tegra_xudc_phy_exit()
3585 phy_exit(xudc->usb3_phy[i]); in tegra_xudc_phy_exit()
3586 phy_exit(xudc->utmi_phy[i]); in tegra_xudc_phy_exit()
3590 static int tegra_xudc_phy_init(struct tegra_xudc *xudc) in tegra_xudc_phy_init() argument
3595 for (i = 0; i < xudc->soc->num_phys; i++) { in tegra_xudc_phy_init()
3596 err = phy_init(xudc->utmi_phy[i]); in tegra_xudc_phy_init()
3598 dev_err(xudc->dev, "UTMI PHY #%u initialization failed: %d\n", i, err); in tegra_xudc_phy_init()
3602 err = phy_init(xudc->usb3_phy[i]); in tegra_xudc_phy_init()
3604 dev_err(xudc->dev, "USB3 PHY #%u initialization failed: %d\n", i, err); in tegra_xudc_phy_init()
3611 tegra_xudc_phy_exit(xudc); in tegra_xudc_phy_init()
3616 "hvdd-usb",
3617 "avddio-usb",
3694 .compatible = "nvidia,tegra210-xudc",
3698 .compatible = "nvidia,tegra186-xudc",
3702 .compatible = "nvidia,tegra194-xudc",
3706 .compatible = "nvidia,tegra234-xudc",
3713 static void tegra_xudc_powerdomain_remove(struct tegra_xudc *xudc) in tegra_xudc_powerdomain_remove() argument
3715 if (xudc->genpd_dl_ss) in tegra_xudc_powerdomain_remove()
3716 device_link_del(xudc->genpd_dl_ss); in tegra_xudc_powerdomain_remove()
3717 if (xudc->genpd_dl_device) in tegra_xudc_powerdomain_remove()
3718 device_link_del(xudc->genpd_dl_device); in tegra_xudc_powerdomain_remove()
3719 if (xudc->genpd_dev_ss) in tegra_xudc_powerdomain_remove()
3720 dev_pm_domain_detach(xudc->genpd_dev_ss, true); in tegra_xudc_powerdomain_remove()
3721 if (xudc->genpd_dev_device) in tegra_xudc_powerdomain_remove()
3722 dev_pm_domain_detach(xudc->genpd_dev_device, true); in tegra_xudc_powerdomain_remove()
3725 static int tegra_xudc_powerdomain_init(struct tegra_xudc *xudc) in tegra_xudc_powerdomain_init() argument
3727 struct device *dev = xudc->dev; in tegra_xudc_powerdomain_init()
3730 xudc->genpd_dev_device = dev_pm_domain_attach_by_name(dev, "dev"); in tegra_xudc_powerdomain_init()
3731 if (IS_ERR(xudc->genpd_dev_device)) { in tegra_xudc_powerdomain_init()
3732 err = PTR_ERR(xudc->genpd_dev_device); in tegra_xudc_powerdomain_init()
3737 xudc->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "ss"); in tegra_xudc_powerdomain_init()
3738 if (IS_ERR(xudc->genpd_dev_ss)) { in tegra_xudc_powerdomain_init()
3739 err = PTR_ERR(xudc->genpd_dev_ss); in tegra_xudc_powerdomain_init()
3744 xudc->genpd_dl_device = device_link_add(dev, xudc->genpd_dev_device, in tegra_xudc_powerdomain_init()
3747 if (!xudc->genpd_dl_device) { in tegra_xudc_powerdomain_init()
3749 return -ENODEV; in tegra_xudc_powerdomain_init()
3752 xudc->genpd_dl_ss = device_link_add(dev, xudc->genpd_dev_ss, in tegra_xudc_powerdomain_init()
3755 if (!xudc->genpd_dl_ss) { in tegra_xudc_powerdomain_init()
3757 return -ENODEV; in tegra_xudc_powerdomain_init()
3765 struct tegra_xudc *xudc; in tegra_xudc_probe() local
3770 xudc = devm_kzalloc(&pdev->dev, sizeof(*xudc), GFP_KERNEL); in tegra_xudc_probe()
3771 if (!xudc) in tegra_xudc_probe()
3772 return -ENOMEM; in tegra_xudc_probe()
3774 xudc->dev = &pdev->dev; in tegra_xudc_probe()
3775 platform_set_drvdata(pdev, xudc); in tegra_xudc_probe()
3777 xudc->soc = of_device_get_match_data(&pdev->dev); in tegra_xudc_probe()
3778 if (!xudc->soc) in tegra_xudc_probe()
3779 return -ENODEV; in tegra_xudc_probe()
3782 xudc->base = devm_ioremap_resource(&pdev->dev, res); in tegra_xudc_probe()
3783 if (IS_ERR(xudc->base)) in tegra_xudc_probe()
3784 return PTR_ERR(xudc->base); in tegra_xudc_probe()
3785 xudc->phys_base = res->start; in tegra_xudc_probe()
3787 xudc->fpci = devm_platform_ioremap_resource_byname(pdev, "fpci"); in tegra_xudc_probe()
3788 if (IS_ERR(xudc->fpci)) in tegra_xudc_probe()
3789 return PTR_ERR(xudc->fpci); in tegra_xudc_probe()
3791 if (xudc->soc->has_ipfs) { in tegra_xudc_probe()
3792 xudc->ipfs = devm_platform_ioremap_resource_byname(pdev, "ipfs"); in tegra_xudc_probe()
3793 if (IS_ERR(xudc->ipfs)) in tegra_xudc_probe()
3794 return PTR_ERR(xudc->ipfs); in tegra_xudc_probe()
3797 xudc->irq = platform_get_irq(pdev, 0); in tegra_xudc_probe()
3798 if (xudc->irq < 0) in tegra_xudc_probe()
3799 return xudc->irq; in tegra_xudc_probe()
3801 err = devm_request_irq(&pdev->dev, xudc->irq, tegra_xudc_irq, 0, in tegra_xudc_probe()
3802 dev_name(&pdev->dev), xudc); in tegra_xudc_probe()
3804 dev_err(xudc->dev, "failed to claim IRQ#%u: %d\n", xudc->irq, in tegra_xudc_probe()
3809 xudc->clks = devm_kcalloc(&pdev->dev, xudc->soc->num_clks, sizeof(*xudc->clks), in tegra_xudc_probe()
3811 if (!xudc->clks) in tegra_xudc_probe()
3812 return -ENOMEM; in tegra_xudc_probe()
3814 for (i = 0; i < xudc->soc->num_clks; i++) in tegra_xudc_probe()
3815 xudc->clks[i].id = xudc->soc->clock_names[i]; in tegra_xudc_probe()
3817 err = devm_clk_bulk_get(&pdev->dev, xudc->soc->num_clks, xudc->clks); in tegra_xudc_probe()
3819 dev_err_probe(xudc->dev, err, "failed to request clocks\n"); in tegra_xudc_probe()
3823 xudc->supplies = devm_kcalloc(&pdev->dev, xudc->soc->num_supplies, in tegra_xudc_probe()
3824 sizeof(*xudc->supplies), GFP_KERNEL); in tegra_xudc_probe()
3825 if (!xudc->supplies) in tegra_xudc_probe()
3826 return -ENOMEM; in tegra_xudc_probe()
3828 for (i = 0; i < xudc->soc->num_supplies; i++) in tegra_xudc_probe()
3829 xudc->supplies[i].supply = xudc->soc->supply_names[i]; in tegra_xudc_probe()
3831 err = devm_regulator_bulk_get(&pdev->dev, xudc->soc->num_supplies, in tegra_xudc_probe()
3832 xudc->supplies); in tegra_xudc_probe()
3834 dev_err_probe(xudc->dev, err, "failed to request regulators\n"); in tegra_xudc_probe()
3838 xudc->padctl = tegra_xusb_padctl_get(&pdev->dev); in tegra_xudc_probe()
3839 if (IS_ERR(xudc->padctl)) in tegra_xudc_probe()
3840 return PTR_ERR(xudc->padctl); in tegra_xudc_probe()
3842 err = regulator_bulk_enable(xudc->soc->num_supplies, xudc->supplies); in tegra_xudc_probe()
3844 dev_err(xudc->dev, "failed to enable regulators: %d\n", err); in tegra_xudc_probe()
3848 err = tegra_xudc_phy_get(xudc); in tegra_xudc_probe()
3852 err = tegra_xudc_powerdomain_init(xudc); in tegra_xudc_probe()
3856 err = tegra_xudc_phy_init(xudc); in tegra_xudc_probe()
3860 err = tegra_xudc_alloc_event_ring(xudc); in tegra_xudc_probe()
3864 err = tegra_xudc_alloc_eps(xudc); in tegra_xudc_probe()
3868 spin_lock_init(&xudc->lock); in tegra_xudc_probe()
3870 init_completion(&xudc->disconnect_complete); in tegra_xudc_probe()
3872 INIT_WORK(&xudc->usb_role_sw_work, tegra_xudc_usb_role_sw_work); in tegra_xudc_probe()
3874 INIT_DELAYED_WORK(&xudc->plc_reset_work, tegra_xudc_plc_reset_work); in tegra_xudc_probe()
3876 INIT_DELAYED_WORK(&xudc->port_reset_war_work, in tegra_xudc_probe()
3879 pm_runtime_enable(&pdev->dev); in tegra_xudc_probe()
3881 xudc->gadget.ops = &tegra_xudc_gadget_ops; in tegra_xudc_probe()
3882 xudc->gadget.ep0 = &xudc->ep[0].usb_ep; in tegra_xudc_probe()
3883 xudc->gadget.name = "tegra-xudc"; in tegra_xudc_probe()
3884 xudc->gadget.max_speed = USB_SPEED_SUPER; in tegra_xudc_probe()
3886 err = usb_add_gadget_udc(&pdev->dev, &xudc->gadget); in tegra_xudc_probe()
3888 dev_err(&pdev->dev, "failed to add USB gadget: %d\n", err); in tegra_xudc_probe()
3892 for (i = 0; i < xudc->soc->num_phys; i++) { in tegra_xudc_probe()
3893 if (!xudc->usbphy[i]) in tegra_xudc_probe()
3896 usb_register_notifier(xudc->usbphy[i], &xudc->vbus_nb); in tegra_xudc_probe()
3897 tegra_xudc_update_data_role(xudc, xudc->usbphy[i]); in tegra_xudc_probe()
3903 pm_runtime_disable(&pdev->dev); in tegra_xudc_probe()
3904 tegra_xudc_free_eps(xudc); in tegra_xudc_probe()
3906 tegra_xudc_free_event_ring(xudc); in tegra_xudc_probe()
3908 tegra_xudc_phy_exit(xudc); in tegra_xudc_probe()
3910 tegra_xudc_powerdomain_remove(xudc); in tegra_xudc_probe()
3912 regulator_bulk_disable(xudc->soc->num_supplies, xudc->supplies); in tegra_xudc_probe()
3914 tegra_xusb_padctl_put(xudc->padctl); in tegra_xudc_probe()
3921 struct tegra_xudc *xudc = platform_get_drvdata(pdev); in tegra_xudc_remove() local
3924 pm_runtime_get_sync(xudc->dev); in tegra_xudc_remove()
3926 cancel_delayed_work_sync(&xudc->plc_reset_work); in tegra_xudc_remove()
3927 cancel_work_sync(&xudc->usb_role_sw_work); in tegra_xudc_remove()
3929 usb_del_gadget_udc(&xudc->gadget); in tegra_xudc_remove()
3931 tegra_xudc_free_eps(xudc); in tegra_xudc_remove()
3932 tegra_xudc_free_event_ring(xudc); in tegra_xudc_remove()
3934 tegra_xudc_powerdomain_remove(xudc); in tegra_xudc_remove()
3936 regulator_bulk_disable(xudc->soc->num_supplies, xudc->supplies); in tegra_xudc_remove()
3938 for (i = 0; i < xudc->soc->num_phys; i++) { in tegra_xudc_remove()
3939 phy_power_off(xudc->utmi_phy[i]); in tegra_xudc_remove()
3940 phy_power_off(xudc->usb3_phy[i]); in tegra_xudc_remove()
3943 tegra_xudc_phy_exit(xudc); in tegra_xudc_remove()
3945 pm_runtime_disable(xudc->dev); in tegra_xudc_remove()
3946 pm_runtime_put(xudc->dev); in tegra_xudc_remove()
3948 tegra_xusb_padctl_put(xudc->padctl); in tegra_xudc_remove()
3951 static int __maybe_unused tegra_xudc_powergate(struct tegra_xudc *xudc) in tegra_xudc_powergate() argument
3955 dev_dbg(xudc->dev, "entering ELPG\n"); in tegra_xudc_powergate()
3957 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_powergate()
3959 xudc->powergated = true; in tegra_xudc_powergate()
3960 xudc->saved_regs.ctrl = xudc_readl(xudc, CTRL); in tegra_xudc_powergate()
3961 xudc->saved_regs.portpm = xudc_readl(xudc, PORTPM); in tegra_xudc_powergate()
3962 xudc_writel(xudc, 0, CTRL); in tegra_xudc_powergate()
3964 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_powergate()
3966 clk_bulk_disable_unprepare(xudc->soc->num_clks, xudc->clks); in tegra_xudc_powergate()
3968 regulator_bulk_disable(xudc->soc->num_supplies, xudc->supplies); in tegra_xudc_powergate()
3970 dev_dbg(xudc->dev, "entering ELPG done\n"); in tegra_xudc_powergate()
3974 static int __maybe_unused tegra_xudc_unpowergate(struct tegra_xudc *xudc) in tegra_xudc_unpowergate() argument
3979 dev_dbg(xudc->dev, "exiting ELPG\n"); in tegra_xudc_unpowergate()
3981 err = regulator_bulk_enable(xudc->soc->num_supplies, in tegra_xudc_unpowergate()
3982 xudc->supplies); in tegra_xudc_unpowergate()
3986 err = clk_bulk_prepare_enable(xudc->soc->num_clks, xudc->clks); in tegra_xudc_unpowergate()
3990 tegra_xudc_fpci_ipfs_init(xudc); in tegra_xudc_unpowergate()
3992 tegra_xudc_device_params_init(xudc); in tegra_xudc_unpowergate()
3994 tegra_xudc_init_event_ring(xudc); in tegra_xudc_unpowergate()
3996 tegra_xudc_init_eps(xudc); in tegra_xudc_unpowergate()
3998 xudc_writel(xudc, xudc->saved_regs.portpm, PORTPM); in tegra_xudc_unpowergate()
3999 xudc_writel(xudc, xudc->saved_regs.ctrl, CTRL); in tegra_xudc_unpowergate()
4001 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_unpowergate()
4002 xudc->powergated = false; in tegra_xudc_unpowergate()
4003 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_unpowergate()
4005 dev_dbg(xudc->dev, "exiting ELPG done\n"); in tegra_xudc_unpowergate()
4011 struct tegra_xudc *xudc = dev_get_drvdata(dev); in tegra_xudc_suspend() local
4014 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_suspend()
4015 xudc->suspended = true; in tegra_xudc_suspend()
4016 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_suspend()
4018 flush_work(&xudc->usb_role_sw_work); in tegra_xudc_suspend()
4022 tegra_xudc_device_mode_off(xudc); in tegra_xudc_suspend()
4023 tegra_xudc_powergate(xudc); in tegra_xudc_suspend()
4033 struct tegra_xudc *xudc = dev_get_drvdata(dev); in tegra_xudc_resume() local
4037 err = tegra_xudc_unpowergate(xudc); in tegra_xudc_resume()
4041 spin_lock_irqsave(&xudc->lock, flags); in tegra_xudc_resume()
4042 xudc->suspended = false; in tegra_xudc_resume()
4043 spin_unlock_irqrestore(&xudc->lock, flags); in tegra_xudc_resume()
4045 schedule_work(&xudc->usb_role_sw_work); in tegra_xudc_resume()
4054 struct tegra_xudc *xudc = dev_get_drvdata(dev); in tegra_xudc_runtime_suspend() local
4056 return tegra_xudc_powergate(xudc); in tegra_xudc_runtime_suspend()
4061 struct tegra_xudc *xudc = dev_get_drvdata(dev); in tegra_xudc_runtime_resume() local
4063 return tegra_xudc_unpowergate(xudc); in tegra_xudc_runtime_resume()
4076 .name = "tegra-xudc",