Lines Matching refs:tegra
278 static inline u32 fpci_readl(struct tegra_xusb *tegra, unsigned int offset) in fpci_readl() argument
280 return readl(tegra->fpci_base + offset); in fpci_readl()
283 static inline void fpci_writel(struct tegra_xusb *tegra, u32 value, in fpci_writel() argument
286 writel(value, tegra->fpci_base + offset); in fpci_writel()
289 static inline u32 ipfs_readl(struct tegra_xusb *tegra, unsigned int offset) in ipfs_readl() argument
291 return readl(tegra->ipfs_base + offset); in ipfs_readl()
294 static inline void ipfs_writel(struct tegra_xusb *tegra, u32 value, in ipfs_writel() argument
297 writel(value, tegra->ipfs_base + offset); in ipfs_writel()
300 static u32 csb_readl(struct tegra_xusb *tegra, unsigned int offset) in csb_readl() argument
305 fpci_writel(tegra, page, XUSB_CFG_ARU_C11_CSBRANGE); in csb_readl()
307 return fpci_readl(tegra, XUSB_CFG_CSB_BASE_ADDR + ofs); in csb_readl()
310 static void csb_writel(struct tegra_xusb *tegra, u32 value, in csb_writel() argument
316 fpci_writel(tegra, page, XUSB_CFG_ARU_C11_CSBRANGE); in csb_writel()
317 fpci_writel(tegra, value, XUSB_CFG_CSB_BASE_ADDR + ofs); in csb_writel()
320 static int tegra_xusb_set_ss_clk(struct tegra_xusb *tegra, in tegra_xusb_set_ss_clk() argument
324 struct clk *clk = tegra->ss_src_clk; in tegra_xusb_set_ss_clk()
338 new_parent_rate = clk_get_rate(tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
345 err = clk_set_parent(clk, tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
361 err = clk_set_parent(clk, tegra->clk_m); in tegra_xusb_set_ss_clk()
372 dev_err(tegra->dev, "Invalid SS rate: %lu Hz\n", rate); in tegra_xusb_set_ss_clk()
377 dev_err(tegra->dev, "SS clock doesn't match requested rate\n"); in tegra_xusb_set_ss_clk()
448 static int tegra_xusb_mbox_send(struct tegra_xusb *tegra, in tegra_xusb_mbox_send() argument
459 value = fpci_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
461 dev_err(tegra->dev, "mailbox is busy\n"); in tegra_xusb_mbox_send()
465 fpci_writel(tegra, MBOX_OWNER_SW, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
467 value = fpci_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
469 dev_err(tegra->dev, "failed to acquire mailbox\n"); in tegra_xusb_mbox_send()
477 fpci_writel(tegra, value, tegra->soc->mbox.data_in); in tegra_xusb_mbox_send()
479 value = fpci_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
481 fpci_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
487 value = fpci_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
495 value = fpci_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
506 struct tegra_xusb *tegra = data; in tegra_xusb_mbox_irq() local
510 value = fpci_readl(tegra, XUSB_CFG_ARU_SMI_INTR); in tegra_xusb_mbox_irq()
511 fpci_writel(tegra, value, XUSB_CFG_ARU_SMI_INTR); in tegra_xusb_mbox_irq()
514 dev_err(tegra->dev, "controller firmware hang\n"); in tegra_xusb_mbox_irq()
519 static void tegra_xusb_mbox_handle(struct tegra_xusb *tegra, in tegra_xusb_mbox_handle() argument
522 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xusb_mbox_handle()
523 const struct tegra_xusb_soc *soc = tegra->soc; in tegra_xusb_mbox_handle()
524 struct device *dev = tegra->dev; in tegra_xusb_mbox_handle()
536 rsp.data = clk_get_rate(tegra->falcon_clk) / 1000; in tegra_xusb_mbox_handle()
546 if (tegra->soc->scale_ss_clock) { in tegra_xusb_mbox_handle()
547 err = tegra_xusb_set_ss_clk(tegra, msg->data * 1000); in tegra_xusb_mbox_handle()
553 rsp.data = clk_get_rate(tegra->ss_src_clk) / 1000; in tegra_xusb_mbox_handle()
655 err = tegra_xusb_mbox_send(tegra, &rsp); in tegra_xusb_mbox_handle()
663 struct tegra_xusb *tegra = data; in tegra_xusb_mbox_thread() local
667 mutex_lock(&tegra->lock); in tegra_xusb_mbox_thread()
669 value = fpci_readl(tegra, tegra->soc->mbox.data_out); in tegra_xusb_mbox_thread()
672 value = fpci_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
674 fpci_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
678 fpci_writel(tegra, MBOX_OWNER_NONE, tegra->soc->mbox.owner); in tegra_xusb_mbox_thread()
680 tegra_xusb_mbox_handle(tegra, &msg); in tegra_xusb_mbox_thread()
682 mutex_unlock(&tegra->lock); in tegra_xusb_mbox_thread()
686 static void tegra_xusb_config(struct tegra_xusb *tegra) in tegra_xusb_config() argument
688 u32 regs = tegra->hcd->rsrc_start; in tegra_xusb_config()
691 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
692 value = ipfs_readl(tegra, IPFS_XUSB_HOST_CONFIGURATION_0); in tegra_xusb_config()
694 ipfs_writel(tegra, value, IPFS_XUSB_HOST_CONFIGURATION_0); in tegra_xusb_config()
700 value = fpci_readl(tegra, XUSB_CFG_4); in tegra_xusb_config()
703 fpci_writel(tegra, value, XUSB_CFG_4); in tegra_xusb_config()
708 value = fpci_readl(tegra, XUSB_CFG_1); in tegra_xusb_config()
710 fpci_writel(tegra, value, XUSB_CFG_1); in tegra_xusb_config()
712 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
714 value = ipfs_readl(tegra, IPFS_XUSB_HOST_INTR_MASK_0); in tegra_xusb_config()
716 ipfs_writel(tegra, value, IPFS_XUSB_HOST_INTR_MASK_0); in tegra_xusb_config()
719 ipfs_writel(tegra, 0x80, IPFS_XUSB_HOST_CLKGATE_HYSTERESIS_0); in tegra_xusb_config()
723 static int tegra_xusb_clk_enable(struct tegra_xusb *tegra) in tegra_xusb_clk_enable() argument
727 err = clk_prepare_enable(tegra->pll_e); in tegra_xusb_clk_enable()
731 err = clk_prepare_enable(tegra->host_clk); in tegra_xusb_clk_enable()
735 err = clk_prepare_enable(tegra->ss_clk); in tegra_xusb_clk_enable()
739 err = clk_prepare_enable(tegra->falcon_clk); in tegra_xusb_clk_enable()
743 err = clk_prepare_enable(tegra->fs_src_clk); in tegra_xusb_clk_enable()
747 err = clk_prepare_enable(tegra->hs_src_clk); in tegra_xusb_clk_enable()
751 if (tegra->soc->scale_ss_clock) { in tegra_xusb_clk_enable()
752 err = tegra_xusb_set_ss_clk(tegra, TEGRA_XHCI_SS_HIGH_SPEED); in tegra_xusb_clk_enable()
760 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_enable()
762 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_enable()
764 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_enable()
766 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_enable()
768 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_enable()
770 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_enable()
774 static void tegra_xusb_clk_disable(struct tegra_xusb *tegra) in tegra_xusb_clk_disable() argument
776 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_disable()
777 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_disable()
778 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_disable()
779 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_disable()
780 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_disable()
781 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_disable()
784 static int tegra_xusb_phy_enable(struct tegra_xusb *tegra) in tegra_xusb_phy_enable() argument
789 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_enable()
790 err = phy_init(tegra->phys[i]); in tegra_xusb_phy_enable()
794 err = phy_power_on(tegra->phys[i]); in tegra_xusb_phy_enable()
796 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
805 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_enable()
806 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
812 static void tegra_xusb_phy_disable(struct tegra_xusb *tegra) in tegra_xusb_phy_disable() argument
816 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_disable()
817 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_disable()
818 phy_exit(tegra->phys[i]); in tegra_xusb_phy_disable()
824 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xusb_runtime_suspend() local
826 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_runtime_suspend()
827 tegra_xusb_clk_disable(tegra); in tegra_xusb_runtime_suspend()
834 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xusb_runtime_resume() local
837 err = tegra_xusb_clk_enable(tegra); in tegra_xusb_runtime_resume()
843 err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_runtime_resume()
852 tegra_xusb_clk_disable(tegra); in tegra_xusb_runtime_resume()
857 static int tegra_xusb_init_context(struct tegra_xusb *tegra) in tegra_xusb_init_context() argument
859 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_init_context()
861 tegra->context.ipfs = devm_kcalloc(tegra->dev, soc->ipfs.num_offsets, in tegra_xusb_init_context()
863 if (!tegra->context.ipfs) in tegra_xusb_init_context()
866 tegra->context.fpci = devm_kcalloc(tegra->dev, soc->fpci.num_offsets, in tegra_xusb_init_context()
868 if (!tegra->context.fpci) in tegra_xusb_init_context()
874 static inline int tegra_xusb_init_context(struct tegra_xusb *tegra) in tegra_xusb_init_context() argument
880 static int tegra_xusb_request_firmware(struct tegra_xusb *tegra) in tegra_xusb_request_firmware() argument
886 err = request_firmware(&fw, tegra->soc->firmware, tegra->dev); in tegra_xusb_request_firmware()
888 dev_err(tegra->dev, "failed to request firmware: %d\n", err); in tegra_xusb_request_firmware()
894 tegra->fw.size = le32_to_cpu(header->fwimg_len); in tegra_xusb_request_firmware()
896 tegra->fw.virt = dma_alloc_coherent(tegra->dev, tegra->fw.size, in tegra_xusb_request_firmware()
897 &tegra->fw.phys, GFP_KERNEL); in tegra_xusb_request_firmware()
898 if (!tegra->fw.virt) { in tegra_xusb_request_firmware()
899 dev_err(tegra->dev, "failed to allocate memory for firmware\n"); in tegra_xusb_request_firmware()
904 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_request_firmware()
905 memcpy(tegra->fw.virt, fw->data, tegra->fw.size); in tegra_xusb_request_firmware()
911 static int tegra_xusb_load_firmware(struct tegra_xusb *tegra) in tegra_xusb_load_firmware() argument
914 struct xhci_cap_regs __iomem *cap = tegra->regs; in tegra_xusb_load_firmware()
916 struct device *dev = tegra->dev; in tegra_xusb_load_firmware()
925 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_load_firmware()
926 op = tegra->regs + HC_LENGTH(readl(&cap->hc_capbase)); in tegra_xusb_load_firmware()
928 if (csb_readl(tegra, XUSB_CSB_MP_ILOAD_BASE_LO) != 0) { in tegra_xusb_load_firmware()
930 csb_readl(tegra, XUSB_FALC_CPUCTL)); in tegra_xusb_load_firmware()
935 csb_writel(tegra, tegra->fw.size, XUSB_CSB_MP_ILOAD_ATTR); in tegra_xusb_load_firmware()
941 address = tegra->fw.phys + sizeof(*header); in tegra_xusb_load_firmware()
942 csb_writel(tegra, address >> 32, XUSB_CSB_MP_ILOAD_BASE_HI); in tegra_xusb_load_firmware()
943 csb_writel(tegra, address, XUSB_CSB_MP_ILOAD_BASE_LO); in tegra_xusb_load_firmware()
946 csb_writel(tegra, APMAP_BOOTPATH, XUSB_CSB_MP_APMAP); in tegra_xusb_load_firmware()
949 csb_writel(tegra, L2IMEMOP_INVALIDATE_ALL, XUSB_CSB_MP_L2IMEMOP_TRIG); in tegra_xusb_load_firmware()
965 csb_writel(tegra, value, XUSB_CSB_MP_L2IMEMOP_SIZE); in tegra_xusb_load_firmware()
968 csb_writel(tegra, L2IMEMOP_LOAD_LOCKED_RESULT, in tegra_xusb_load_firmware()
972 csb_writel(tegra, code_size_blocks, XUSB_FALC_IMFILLCTL); in tegra_xusb_load_firmware()
978 csb_writel(tegra, value, XUSB_FALC_IMFILLRNG1); in tegra_xusb_load_firmware()
980 csb_writel(tegra, 0, XUSB_FALC_DMACTL); in tegra_xusb_load_firmware()
983 #define tegra_csb_readl(offset) csb_readl(tegra, offset) in tegra_xusb_load_firmware()
993 csb_writel(tegra, le32_to_cpu(header->boot_codetag), in tegra_xusb_load_firmware()
997 csb_writel(tegra, CPUCTL_STARTCPU, XUSB_FALC_CPUCTL); in tegra_xusb_load_firmware()
1011 value = csb_readl(tegra, XUSB_FALC_CPUCTL); in tegra_xusb_load_firmware()
1027 struct tegra_xusb *tegra) in tegra_xusb_powerdomain_remove() argument
1029 if (tegra->genpd_dl_ss) in tegra_xusb_powerdomain_remove()
1030 device_link_del(tegra->genpd_dl_ss); in tegra_xusb_powerdomain_remove()
1031 if (tegra->genpd_dl_host) in tegra_xusb_powerdomain_remove()
1032 device_link_del(tegra->genpd_dl_host); in tegra_xusb_powerdomain_remove()
1033 if (!IS_ERR_OR_NULL(tegra->genpd_dev_ss)) in tegra_xusb_powerdomain_remove()
1034 dev_pm_domain_detach(tegra->genpd_dev_ss, true); in tegra_xusb_powerdomain_remove()
1035 if (!IS_ERR_OR_NULL(tegra->genpd_dev_host)) in tegra_xusb_powerdomain_remove()
1036 dev_pm_domain_detach(tegra->genpd_dev_host, true); in tegra_xusb_powerdomain_remove()
1040 struct tegra_xusb *tegra) in tegra_xusb_powerdomain_init() argument
1044 tegra->genpd_dev_host = dev_pm_domain_attach_by_name(dev, "xusb_host"); in tegra_xusb_powerdomain_init()
1045 if (IS_ERR_OR_NULL(tegra->genpd_dev_host)) { in tegra_xusb_powerdomain_init()
1046 err = PTR_ERR(tegra->genpd_dev_host) ? : -ENODATA; in tegra_xusb_powerdomain_init()
1051 tegra->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "xusb_ss"); in tegra_xusb_powerdomain_init()
1052 if (IS_ERR_OR_NULL(tegra->genpd_dev_ss)) { in tegra_xusb_powerdomain_init()
1053 err = PTR_ERR(tegra->genpd_dev_ss) ? : -ENODATA; in tegra_xusb_powerdomain_init()
1058 tegra->genpd_dl_host = device_link_add(dev, tegra->genpd_dev_host, in tegra_xusb_powerdomain_init()
1061 if (!tegra->genpd_dl_host) { in tegra_xusb_powerdomain_init()
1066 tegra->genpd_dl_ss = device_link_add(dev, tegra->genpd_dev_ss, in tegra_xusb_powerdomain_init()
1069 if (!tegra->genpd_dl_ss) { in tegra_xusb_powerdomain_init()
1077 static int __tegra_xusb_enable_firmware_messages(struct tegra_xusb *tegra) in __tegra_xusb_enable_firmware_messages() argument
1086 err = tegra_xusb_mbox_send(tegra, &msg); in __tegra_xusb_enable_firmware_messages()
1088 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in __tegra_xusb_enable_firmware_messages()
1093 static int tegra_xusb_enable_firmware_messages(struct tegra_xusb *tegra) in tegra_xusb_enable_firmware_messages() argument
1097 mutex_lock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1098 err = __tegra_xusb_enable_firmware_messages(tegra); in tegra_xusb_enable_firmware_messages()
1099 mutex_unlock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1104 static void tegra_xhci_set_port_power(struct tegra_xusb *tegra, bool main, in tegra_xhci_set_port_power() argument
1107 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_set_port_power()
1111 u16 wIndex = main ? tegra->otg_usb2_port + 1 : tegra->otg_usb3_port + 1; in tegra_xhci_set_port_power()
1116 dev_dbg(tegra->dev, "%s():%s %s port power\n", __func__, in tegra_xhci_set_port_power()
1135 dev_info(tegra->dev, "failed to %s %s PP %d\n", in tegra_xhci_set_port_power()
1140 static struct phy *tegra_xusb_get_phy(struct tegra_xusb *tegra, char *name, in tegra_xusb_get_phy() argument
1145 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_get_phy()
1146 if (!strncmp(tegra->soc->phy_types[i].name, name, in tegra_xusb_get_phy()
1148 return tegra->phys[phy_count+port]; in tegra_xusb_get_phy()
1150 phy_count += tegra->soc->phy_types[i].num; in tegra_xusb_get_phy()
1158 struct tegra_xusb *tegra = container_of(work, struct tegra_xusb, in tegra_xhci_id_work() local
1160 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_id_work()
1162 struct phy *phy = tegra_xusb_get_phy(tegra, "usb2", in tegra_xhci_id_work()
1163 tegra->otg_usb2_port); in tegra_xhci_id_work()
1167 dev_dbg(tegra->dev, "host mode %s\n", tegra->host_mode ? "on" : "off"); in tegra_xhci_id_work()
1169 mutex_lock(&tegra->lock); in tegra_xhci_id_work()
1171 if (tegra->host_mode) in tegra_xhci_id_work()
1176 mutex_unlock(&tegra->lock); in tegra_xhci_id_work()
1178 if (tegra->host_mode) { in tegra_xhci_id_work()
1180 if (tegra->otg_usb3_port >= 0) { in tegra_xhci_id_work()
1181 if (tegra->soc->otg_reset_sspi) { in tegra_xhci_id_work()
1185 0, tegra->otg_usb3_port+1, in tegra_xhci_id_work()
1188 tegra_xhci_set_port_power(tegra, false, in tegra_xhci_id_work()
1193 msg.data = tegra->otg_usb3_port+1; in tegra_xhci_id_work()
1195 ret = tegra_xusb_mbox_send(tegra, &msg); in tegra_xhci_id_work()
1197 dev_info(tegra->dev, in tegra_xhci_id_work()
1203 tegra_xhci_set_port_power(tegra, false, true); in tegra_xhci_id_work()
1206 tegra_xhci_set_port_power(tegra, true, true); in tegra_xhci_id_work()
1209 if (tegra->otg_usb3_port >= 0) in tegra_xhci_id_work()
1210 tegra_xhci_set_port_power(tegra, false, false); in tegra_xhci_id_work()
1212 tegra_xhci_set_port_power(tegra, true, false); in tegra_xhci_id_work()
1216 static int tegra_xusb_get_usb2_port(struct tegra_xusb *tegra, in tegra_xusb_get_usb2_port() argument
1221 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_get_usb2_port()
1222 if (tegra->usbphy[i] && usbphy == tegra->usbphy[i]) in tegra_xusb_get_usb2_port()
1232 struct tegra_xusb *tegra = container_of(nb, struct tegra_xusb, in tegra_xhci_id_notify() local
1236 dev_dbg(tegra->dev, "%s(): action is %d", __func__, usbphy->last_event); in tegra_xhci_id_notify()
1238 if ((tegra->host_mode && usbphy->last_event == USB_EVENT_ID) || in tegra_xhci_id_notify()
1239 (!tegra->host_mode && usbphy->last_event != USB_EVENT_ID)) { in tegra_xhci_id_notify()
1240 dev_dbg(tegra->dev, "Same role(%d) received. Ignore", in tegra_xhci_id_notify()
1241 tegra->host_mode); in tegra_xhci_id_notify()
1245 tegra->otg_usb2_port = tegra_xusb_get_usb2_port(tegra, usbphy); in tegra_xhci_id_notify()
1246 tegra->otg_usb3_port = tegra_xusb_padctl_get_usb3_companion( in tegra_xhci_id_notify()
1247 tegra->padctl, in tegra_xhci_id_notify()
1248 tegra->otg_usb2_port); in tegra_xhci_id_notify()
1250 tegra->host_mode = (usbphy->last_event == USB_EVENT_ID) ? true : false; in tegra_xhci_id_notify()
1252 schedule_work(&tegra->id_work); in tegra_xhci_id_notify()
1257 static int tegra_xusb_init_usb_phy(struct tegra_xusb *tegra) in tegra_xusb_init_usb_phy() argument
1261 tegra->usbphy = devm_kcalloc(tegra->dev, tegra->num_usb_phys, in tegra_xusb_init_usb_phy()
1262 sizeof(*tegra->usbphy), GFP_KERNEL); in tegra_xusb_init_usb_phy()
1263 if (!tegra->usbphy) in tegra_xusb_init_usb_phy()
1266 INIT_WORK(&tegra->id_work, tegra_xhci_id_work); in tegra_xusb_init_usb_phy()
1267 tegra->id_nb.notifier_call = tegra_xhci_id_notify; in tegra_xusb_init_usb_phy()
1268 tegra->otg_usb2_port = -EINVAL; in tegra_xusb_init_usb_phy()
1269 tegra->otg_usb3_port = -EINVAL; in tegra_xusb_init_usb_phy()
1271 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_init_usb_phy()
1272 struct phy *phy = tegra_xusb_get_phy(tegra, "usb2", i); in tegra_xusb_init_usb_phy()
1277 tegra->usbphy[i] = devm_usb_get_phy_by_node(tegra->dev, in tegra_xusb_init_usb_phy()
1279 &tegra->id_nb); in tegra_xusb_init_usb_phy()
1280 if (!IS_ERR(tegra->usbphy[i])) { in tegra_xusb_init_usb_phy()
1281 dev_dbg(tegra->dev, "usbphy-%d registered", i); in tegra_xusb_init_usb_phy()
1282 otg_set_host(tegra->usbphy[i]->otg, &tegra->hcd->self); in tegra_xusb_init_usb_phy()
1287 tegra->usbphy[i] = NULL; in tegra_xusb_init_usb_phy()
1294 static void tegra_xusb_deinit_usb_phy(struct tegra_xusb *tegra) in tegra_xusb_deinit_usb_phy() argument
1298 cancel_work_sync(&tegra->id_work); in tegra_xusb_deinit_usb_phy()
1300 for (i = 0; i < tegra->num_usb_phys; i++) in tegra_xusb_deinit_usb_phy()
1301 if (tegra->usbphy[i]) in tegra_xusb_deinit_usb_phy()
1302 otg_set_host(tegra->usbphy[i]->otg, NULL); in tegra_xusb_deinit_usb_phy()
1307 struct tegra_xusb *tegra; in tegra_xusb_probe() local
1316 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_xusb_probe()
1317 if (!tegra) in tegra_xusb_probe()
1320 tegra->soc = of_device_get_match_data(&pdev->dev); in tegra_xusb_probe()
1321 mutex_init(&tegra->lock); in tegra_xusb_probe()
1322 tegra->dev = &pdev->dev; in tegra_xusb_probe()
1324 err = tegra_xusb_init_context(tegra); in tegra_xusb_probe()
1329 tegra->regs = devm_ioremap_resource(&pdev->dev, regs); in tegra_xusb_probe()
1330 if (IS_ERR(tegra->regs)) in tegra_xusb_probe()
1331 return PTR_ERR(tegra->regs); in tegra_xusb_probe()
1333 tegra->fpci_base = devm_platform_ioremap_resource(pdev, 1); in tegra_xusb_probe()
1334 if (IS_ERR(tegra->fpci_base)) in tegra_xusb_probe()
1335 return PTR_ERR(tegra->fpci_base); in tegra_xusb_probe()
1337 if (tegra->soc->has_ipfs) { in tegra_xusb_probe()
1338 tegra->ipfs_base = devm_platform_ioremap_resource(pdev, 2); in tegra_xusb_probe()
1339 if (IS_ERR(tegra->ipfs_base)) in tegra_xusb_probe()
1340 return PTR_ERR(tegra->ipfs_base); in tegra_xusb_probe()
1343 tegra->xhci_irq = platform_get_irq(pdev, 0); in tegra_xusb_probe()
1344 if (tegra->xhci_irq < 0) in tegra_xusb_probe()
1345 return tegra->xhci_irq; in tegra_xusb_probe()
1347 tegra->mbox_irq = platform_get_irq(pdev, 1); in tegra_xusb_probe()
1348 if (tegra->mbox_irq < 0) in tegra_xusb_probe()
1349 return tegra->mbox_irq; in tegra_xusb_probe()
1351 tegra->padctl = tegra_xusb_padctl_get(&pdev->dev); in tegra_xusb_probe()
1352 if (IS_ERR(tegra->padctl)) in tegra_xusb_probe()
1353 return PTR_ERR(tegra->padctl); in tegra_xusb_probe()
1355 tegra->host_clk = devm_clk_get(&pdev->dev, "xusb_host"); in tegra_xusb_probe()
1356 if (IS_ERR(tegra->host_clk)) { in tegra_xusb_probe()
1357 err = PTR_ERR(tegra->host_clk); in tegra_xusb_probe()
1362 tegra->falcon_clk = devm_clk_get(&pdev->dev, "xusb_falcon_src"); in tegra_xusb_probe()
1363 if (IS_ERR(tegra->falcon_clk)) { in tegra_xusb_probe()
1364 err = PTR_ERR(tegra->falcon_clk); in tegra_xusb_probe()
1369 tegra->ss_clk = devm_clk_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1370 if (IS_ERR(tegra->ss_clk)) { in tegra_xusb_probe()
1371 err = PTR_ERR(tegra->ss_clk); in tegra_xusb_probe()
1376 tegra->ss_src_clk = devm_clk_get(&pdev->dev, "xusb_ss_src"); in tegra_xusb_probe()
1377 if (IS_ERR(tegra->ss_src_clk)) { in tegra_xusb_probe()
1378 err = PTR_ERR(tegra->ss_src_clk); in tegra_xusb_probe()
1383 tegra->hs_src_clk = devm_clk_get(&pdev->dev, "xusb_hs_src"); in tegra_xusb_probe()
1384 if (IS_ERR(tegra->hs_src_clk)) { in tegra_xusb_probe()
1385 err = PTR_ERR(tegra->hs_src_clk); in tegra_xusb_probe()
1390 tegra->fs_src_clk = devm_clk_get(&pdev->dev, "xusb_fs_src"); in tegra_xusb_probe()
1391 if (IS_ERR(tegra->fs_src_clk)) { in tegra_xusb_probe()
1392 err = PTR_ERR(tegra->fs_src_clk); in tegra_xusb_probe()
1397 tegra->pll_u_480m = devm_clk_get(&pdev->dev, "pll_u_480m"); in tegra_xusb_probe()
1398 if (IS_ERR(tegra->pll_u_480m)) { in tegra_xusb_probe()
1399 err = PTR_ERR(tegra->pll_u_480m); in tegra_xusb_probe()
1404 tegra->clk_m = devm_clk_get(&pdev->dev, "clk_m"); in tegra_xusb_probe()
1405 if (IS_ERR(tegra->clk_m)) { in tegra_xusb_probe()
1406 err = PTR_ERR(tegra->clk_m); in tegra_xusb_probe()
1411 tegra->pll_e = devm_clk_get(&pdev->dev, "pll_e"); in tegra_xusb_probe()
1412 if (IS_ERR(tegra->pll_e)) { in tegra_xusb_probe()
1413 err = PTR_ERR(tegra->pll_e); in tegra_xusb_probe()
1419 tegra->host_rst = devm_reset_control_get(&pdev->dev, in tegra_xusb_probe()
1421 if (IS_ERR(tegra->host_rst)) { in tegra_xusb_probe()
1422 err = PTR_ERR(tegra->host_rst); in tegra_xusb_probe()
1428 tegra->ss_rst = devm_reset_control_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1429 if (IS_ERR(tegra->ss_rst)) { in tegra_xusb_probe()
1430 err = PTR_ERR(tegra->ss_rst); in tegra_xusb_probe()
1437 tegra->ss_clk, in tegra_xusb_probe()
1438 tegra->ss_rst); in tegra_xusb_probe()
1446 tegra->host_clk, in tegra_xusb_probe()
1447 tegra->host_rst); in tegra_xusb_probe()
1455 err = tegra_xusb_powerdomain_init(&pdev->dev, tegra); in tegra_xusb_probe()
1460 tegra->supplies = devm_kcalloc(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1461 sizeof(*tegra->supplies), GFP_KERNEL); in tegra_xusb_probe()
1462 if (!tegra->supplies) { in tegra_xusb_probe()
1467 regulator_bulk_set_supply_names(tegra->supplies, in tegra_xusb_probe()
1468 tegra->soc->supply_names, in tegra_xusb_probe()
1469 tegra->soc->num_supplies); in tegra_xusb_probe()
1471 err = devm_regulator_bulk_get(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1472 tegra->supplies); in tegra_xusb_probe()
1478 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1479 if (!strncmp(tegra->soc->phy_types[i].name, "usb2", 4)) in tegra_xusb_probe()
1480 tegra->num_usb_phys = tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1481 tegra->num_phys += tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1484 tegra->phys = devm_kcalloc(&pdev->dev, tegra->num_phys, in tegra_xusb_probe()
1485 sizeof(*tegra->phys), GFP_KERNEL); in tegra_xusb_probe()
1486 if (!tegra->phys) { in tegra_xusb_probe()
1491 for (i = 0, k = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1494 for (j = 0; j < tegra->soc->phy_types[i].num; j++) { in tegra_xusb_probe()
1496 tegra->soc->phy_types[i].name, j); in tegra_xusb_probe()
1507 tegra->phys[k++] = phy; in tegra_xusb_probe()
1511 tegra->hcd = usb_create_hcd(&tegra_xhci_hc_driver, &pdev->dev, in tegra_xusb_probe()
1513 if (!tegra->hcd) { in tegra_xusb_probe()
1518 tegra->hcd->regs = tegra->regs; in tegra_xusb_probe()
1519 tegra->hcd->rsrc_start = regs->start; in tegra_xusb_probe()
1520 tegra->hcd->rsrc_len = resource_size(regs); in tegra_xusb_probe()
1526 platform_set_drvdata(pdev, tegra); in tegra_xusb_probe()
1528 err = tegra_xusb_phy_enable(tegra); in tegra_xusb_probe()
1538 err = dma_set_mask_and_coherent(tegra->dev, DMA_BIT_MASK(40)); in tegra_xusb_probe()
1544 err = tegra_xusb_request_firmware(tegra); in tegra_xusb_probe()
1562 tegra_xusb_config(tegra); in tegra_xusb_probe()
1564 err = tegra_xusb_load_firmware(tegra); in tegra_xusb_probe()
1570 err = usb_add_hcd(tegra->hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1576 device_wakeup_enable(tegra->hcd->self.controller); in tegra_xusb_probe()
1578 xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_probe()
1583 tegra->hcd); in tegra_xusb_probe()
1590 err = usb_add_hcd(xhci->shared_hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1596 err = tegra_xusb_enable_firmware_messages(tegra); in tegra_xusb_probe()
1602 err = devm_request_threaded_irq(&pdev->dev, tegra->mbox_irq, in tegra_xusb_probe()
1605 dev_name(&pdev->dev), tegra); in tegra_xusb_probe()
1611 err = tegra_xusb_init_usb_phy(tegra); in tegra_xusb_probe()
1624 usb_remove_hcd(tegra->hcd); in tegra_xusb_probe()
1629 usb_put_hcd(tegra->hcd); in tegra_xusb_probe()
1631 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_probe()
1632 tegra->fw.phys); in tegra_xusb_probe()
1634 tegra_xusb_phy_disable(tegra); in tegra_xusb_probe()
1641 tegra_xusb_powerdomain_remove(&pdev->dev, tegra); in tegra_xusb_probe()
1644 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_probe()
1650 struct tegra_xusb *tegra = platform_get_drvdata(pdev); in tegra_xusb_remove() local
1651 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_remove()
1653 tegra_xusb_deinit_usb_phy(tegra); in tegra_xusb_remove()
1658 usb_remove_hcd(tegra->hcd); in tegra_xusb_remove()
1659 usb_put_hcd(tegra->hcd); in tegra_xusb_remove()
1661 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_remove()
1662 tegra->fw.phys); in tegra_xusb_remove()
1671 tegra_xusb_powerdomain_remove(&pdev->dev, tegra); in tegra_xusb_remove()
1674 tegra_xusb_phy_disable(tegra); in tegra_xusb_remove()
1676 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_remove()
1704 static int tegra_xusb_check_ports(struct tegra_xusb *tegra) in tegra_xusb_check_ports() argument
1706 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_check_ports()
1721 static void tegra_xusb_save_context(struct tegra_xusb *tegra) in tegra_xusb_save_context() argument
1723 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_save_context()
1724 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_save_context()
1729 ctx->ipfs[i] = ipfs_readl(tegra, soc->ipfs.offsets[i]); in tegra_xusb_save_context()
1734 ctx->fpci[i] = fpci_readl(tegra, soc->fpci.offsets[i]); in tegra_xusb_save_context()
1738 static void tegra_xusb_restore_context(struct tegra_xusb *tegra) in tegra_xusb_restore_context() argument
1740 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_restore_context()
1741 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_restore_context()
1746 fpci_writel(tegra, ctx->fpci[i], soc->fpci.offsets[i]); in tegra_xusb_restore_context()
1751 ipfs_writel(tegra, ctx->ipfs[i], soc->ipfs.offsets[i]); in tegra_xusb_restore_context()
1755 static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool wakeup) in tegra_xusb_enter_elpg() argument
1757 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_enter_elpg()
1760 err = tegra_xusb_check_ports(tegra); in tegra_xusb_enter_elpg()
1762 dev_err(tegra->dev, "not all ports suspended: %d\n", err); in tegra_xusb_enter_elpg()
1768 dev_err(tegra->dev, "failed to suspend XHCI: %d\n", err); in tegra_xusb_enter_elpg()
1772 tegra_xusb_save_context(tegra); in tegra_xusb_enter_elpg()
1773 tegra_xusb_phy_disable(tegra); in tegra_xusb_enter_elpg()
1774 tegra_xusb_clk_disable(tegra); in tegra_xusb_enter_elpg()
1779 static int tegra_xusb_exit_elpg(struct tegra_xusb *tegra, bool wakeup) in tegra_xusb_exit_elpg() argument
1781 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_exit_elpg()
1784 err = tegra_xusb_clk_enable(tegra); in tegra_xusb_exit_elpg()
1786 dev_err(tegra->dev, "failed to enable clocks: %d\n", err); in tegra_xusb_exit_elpg()
1790 err = tegra_xusb_phy_enable(tegra); in tegra_xusb_exit_elpg()
1792 dev_err(tegra->dev, "failed to enable PHYs: %d\n", err); in tegra_xusb_exit_elpg()
1796 tegra_xusb_config(tegra); in tegra_xusb_exit_elpg()
1797 tegra_xusb_restore_context(tegra); in tegra_xusb_exit_elpg()
1799 err = tegra_xusb_load_firmware(tegra); in tegra_xusb_exit_elpg()
1801 dev_err(tegra->dev, "failed to load firmware: %d\n", err); in tegra_xusb_exit_elpg()
1805 err = __tegra_xusb_enable_firmware_messages(tegra); in tegra_xusb_exit_elpg()
1807 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in tegra_xusb_exit_elpg()
1813 dev_err(tegra->dev, "failed to resume XHCI: %d\n", err); in tegra_xusb_exit_elpg()
1820 tegra_xusb_phy_disable(tegra); in tegra_xusb_exit_elpg()
1822 tegra_xusb_clk_disable(tegra); in tegra_xusb_exit_elpg()
1828 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xusb_suspend() local
1832 synchronize_irq(tegra->mbox_irq); in tegra_xusb_suspend()
1834 mutex_lock(&tegra->lock); in tegra_xusb_suspend()
1835 err = tegra_xusb_enter_elpg(tegra, wakeup); in tegra_xusb_suspend()
1836 mutex_unlock(&tegra->lock); in tegra_xusb_suspend()
1843 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xusb_resume() local
1847 mutex_lock(&tegra->lock); in tegra_xusb_resume()
1848 err = tegra_xusb_exit_elpg(tegra, wakeup); in tegra_xusb_resume()
1849 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2064 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xhci_quirks() local
2067 if (tegra && tegra->soc->lpm_support) in tegra_xhci_quirks()