Lines Matching full:tegra
3 * NVIDIA Tegra xHCI host controller driver
20 #include <linux/phy/tegra/xusb.h>
33 #include <soc/tegra/pmc.h>
219 u32 (*mbox_reg_readl)(struct tegra_xusb *tegra, unsigned int offset);
220 void (*mbox_reg_writel)(struct tegra_xusb *tegra, u32 value, unsigned int offset);
221 u32 (*csb_reg_readl)(struct tegra_xusb *tegra, unsigned int offset);
222 void (*csb_reg_writel)(struct tegra_xusb *tegra, u32 value, unsigned int offset);
320 static inline u32 fpci_readl(struct tegra_xusb *tegra, unsigned int offset) in fpci_readl() argument
322 return readl(tegra->fpci_base + offset); in fpci_readl()
325 static inline void fpci_writel(struct tegra_xusb *tegra, u32 value, in fpci_writel() argument
328 writel(value, tegra->fpci_base + offset); in fpci_writel()
331 static inline u32 ipfs_readl(struct tegra_xusb *tegra, unsigned int offset) in ipfs_readl() argument
333 return readl(tegra->ipfs_base + offset); in ipfs_readl()
336 static inline void ipfs_writel(struct tegra_xusb *tegra, u32 value, in ipfs_writel() argument
339 writel(value, tegra->ipfs_base + offset); in ipfs_writel()
342 static inline u32 bar2_readl(struct tegra_xusb *tegra, unsigned int offset) in bar2_readl() argument
344 return readl(tegra->bar2_base + offset); in bar2_readl()
347 static inline void bar2_writel(struct tegra_xusb *tegra, u32 value, in bar2_writel() argument
350 writel(value, tegra->bar2_base + offset); in bar2_writel()
353 static u32 csb_readl(struct tegra_xusb *tegra, unsigned int offset) in csb_readl() argument
355 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in csb_readl()
357 return ops->csb_reg_readl(tegra, offset); in csb_readl()
360 static void csb_writel(struct tegra_xusb *tegra, u32 value, in csb_writel() argument
363 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in csb_writel()
365 ops->csb_reg_writel(tegra, value, offset); in csb_writel()
368 static u32 fpci_csb_readl(struct tegra_xusb *tegra, unsigned int offset) in fpci_csb_readl() argument
373 fpci_writel(tegra, page, XUSB_CFG_ARU_C11_CSBRANGE); in fpci_csb_readl()
375 return fpci_readl(tegra, XUSB_CFG_CSB_BASE_ADDR + ofs); in fpci_csb_readl()
378 static void fpci_csb_writel(struct tegra_xusb *tegra, u32 value, in fpci_csb_writel() argument
384 fpci_writel(tegra, page, XUSB_CFG_ARU_C11_CSBRANGE); in fpci_csb_writel()
385 fpci_writel(tegra, value, XUSB_CFG_CSB_BASE_ADDR + ofs); in fpci_csb_writel()
388 static u32 bar2_csb_readl(struct tegra_xusb *tegra, unsigned int offset) in bar2_csb_readl() argument
393 bar2_writel(tegra, page, XUSB_BAR2_ARU_C11_CSBRANGE); in bar2_csb_readl()
395 return bar2_readl(tegra, XUSB_BAR2_CSB_BASE_ADDR + ofs); in bar2_csb_readl()
398 static void bar2_csb_writel(struct tegra_xusb *tegra, u32 value, in bar2_csb_writel() argument
404 bar2_writel(tegra, page, XUSB_BAR2_ARU_C11_CSBRANGE); in bar2_csb_writel()
405 bar2_writel(tegra, value, XUSB_BAR2_CSB_BASE_ADDR + ofs); in bar2_csb_writel()
408 static int tegra_xusb_set_ss_clk(struct tegra_xusb *tegra, in tegra_xusb_set_ss_clk() argument
412 struct clk *clk = tegra->ss_src_clk; in tegra_xusb_set_ss_clk()
426 new_parent_rate = clk_get_rate(tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
433 err = clk_set_parent(clk, tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
449 err = clk_set_parent(clk, tegra->clk_m); in tegra_xusb_set_ss_clk()
460 dev_err(tegra->dev, "Invalid SS rate: %lu Hz\n", rate); in tegra_xusb_set_ss_clk()
465 dev_err(tegra->dev, "SS clock doesn't match requested rate\n"); in tegra_xusb_set_ss_clk()
536 static int tegra_xusb_mbox_send(struct tegra_xusb *tegra, in tegra_xusb_mbox_send() argument
539 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_send()
548 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
550 dev_err(tegra->dev, "mailbox is busy\n"); in tegra_xusb_mbox_send()
554 ops->mbox_reg_writel(tegra, MBOX_OWNER_SW, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
556 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
558 dev_err(tegra->dev, "failed to acquire mailbox\n"); in tegra_xusb_mbox_send()
566 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.data_in); in tegra_xusb_mbox_send()
568 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
570 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
576 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
584 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
595 struct tegra_xusb *tegra = data; in tegra_xusb_mbox_irq() local
596 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_irq()
600 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.smi_intr); in tegra_xusb_mbox_irq()
601 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.smi_intr); in tegra_xusb_mbox_irq()
604 dev_err(tegra->dev, "controller firmware hang\n"); in tegra_xusb_mbox_irq()
609 static void tegra_xusb_mbox_handle(struct tegra_xusb *tegra, in tegra_xusb_mbox_handle() argument
612 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xusb_mbox_handle()
613 const struct tegra_xusb_soc *soc = tegra->soc; in tegra_xusb_mbox_handle()
614 struct device *dev = tegra->dev; in tegra_xusb_mbox_handle()
626 rsp.data = clk_get_rate(tegra->falcon_clk) / 1000; in tegra_xusb_mbox_handle()
636 if (tegra->soc->scale_ss_clock) { in tegra_xusb_mbox_handle()
637 err = tegra_xusb_set_ss_clk(tegra, msg->data * 1000); in tegra_xusb_mbox_handle()
643 rsp.data = clk_get_rate(tegra->ss_src_clk) / 1000; in tegra_xusb_mbox_handle()
745 err = tegra_xusb_mbox_send(tegra, &rsp); in tegra_xusb_mbox_handle()
753 struct tegra_xusb *tegra = data; in tegra_xusb_mbox_thread() local
754 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_thread()
758 mutex_lock(&tegra->lock); in tegra_xusb_mbox_thread()
760 if (pm_runtime_suspended(tegra->dev) || tegra->suspended) in tegra_xusb_mbox_thread()
763 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.data_out); in tegra_xusb_mbox_thread()
766 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
768 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
772 ops->mbox_reg_writel(tegra, MBOX_OWNER_NONE, tegra->soc->mbox.owner); in tegra_xusb_mbox_thread()
774 tegra_xusb_mbox_handle(tegra, &msg); in tegra_xusb_mbox_thread()
777 mutex_unlock(&tegra->lock); in tegra_xusb_mbox_thread()
781 static void tegra_xusb_config(struct tegra_xusb *tegra) in tegra_xusb_config() argument
783 u32 regs = tegra->hcd->rsrc_start; in tegra_xusb_config()
786 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
787 value = ipfs_readl(tegra, IPFS_XUSB_HOST_CONFIGURATION_0); in tegra_xusb_config()
789 ipfs_writel(tegra, value, IPFS_XUSB_HOST_CONFIGURATION_0); in tegra_xusb_config()
795 value = fpci_readl(tegra, XUSB_CFG_4); in tegra_xusb_config()
798 fpci_writel(tegra, value, XUSB_CFG_4); in tegra_xusb_config()
801 if (tegra->bar2) { in tegra_xusb_config()
802 value = fpci_readl(tegra, XUSB_CFG_7); in tegra_xusb_config()
804 value |= tegra->bar2->start & in tegra_xusb_config()
806 fpci_writel(tegra, value, XUSB_CFG_7); in tegra_xusb_config()
812 value = fpci_readl(tegra, XUSB_CFG_1); in tegra_xusb_config()
814 fpci_writel(tegra, value, XUSB_CFG_1); in tegra_xusb_config()
816 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
818 value = ipfs_readl(tegra, IPFS_XUSB_HOST_INTR_MASK_0); in tegra_xusb_config()
820 ipfs_writel(tegra, value, IPFS_XUSB_HOST_INTR_MASK_0); in tegra_xusb_config()
823 ipfs_writel(tegra, 0x80, IPFS_XUSB_HOST_CLKGATE_HYSTERESIS_0); in tegra_xusb_config()
827 static int tegra_xusb_clk_enable(struct tegra_xusb *tegra) in tegra_xusb_clk_enable() argument
831 err = clk_prepare_enable(tegra->pll_e); in tegra_xusb_clk_enable()
835 err = clk_prepare_enable(tegra->host_clk); in tegra_xusb_clk_enable()
839 err = clk_prepare_enable(tegra->ss_clk); in tegra_xusb_clk_enable()
843 err = clk_prepare_enable(tegra->falcon_clk); in tegra_xusb_clk_enable()
847 err = clk_prepare_enable(tegra->fs_src_clk); in tegra_xusb_clk_enable()
851 err = clk_prepare_enable(tegra->hs_src_clk); in tegra_xusb_clk_enable()
855 if (tegra->soc->scale_ss_clock) { in tegra_xusb_clk_enable()
856 err = tegra_xusb_set_ss_clk(tegra, TEGRA_XHCI_SS_HIGH_SPEED); in tegra_xusb_clk_enable()
864 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_enable()
866 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_enable()
868 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_enable()
870 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_enable()
872 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_enable()
874 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_enable()
878 static void tegra_xusb_clk_disable(struct tegra_xusb *tegra) in tegra_xusb_clk_disable() argument
880 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_disable()
881 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_disable()
882 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_disable()
883 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_disable()
884 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_disable()
885 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_disable()
888 static int tegra_xusb_phy_enable(struct tegra_xusb *tegra) in tegra_xusb_phy_enable() argument
893 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_enable()
894 err = phy_init(tegra->phys[i]); in tegra_xusb_phy_enable()
898 err = phy_power_on(tegra->phys[i]); in tegra_xusb_phy_enable()
900 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
909 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_enable()
910 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
916 static void tegra_xusb_phy_disable(struct tegra_xusb *tegra) in tegra_xusb_phy_disable() argument
920 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_disable()
921 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_disable()
922 phy_exit(tegra->phys[i]); in tegra_xusb_phy_disable()
927 static int tegra_xusb_init_context(struct tegra_xusb *tegra) in tegra_xusb_init_context() argument
929 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_init_context()
931 tegra->context.ipfs = devm_kcalloc(tegra->dev, soc->ipfs.num_offsets, in tegra_xusb_init_context()
933 if (!tegra->context.ipfs) in tegra_xusb_init_context()
936 tegra->context.fpci = devm_kcalloc(tegra->dev, soc->fpci.num_offsets, in tegra_xusb_init_context()
938 if (!tegra->context.fpci) in tegra_xusb_init_context()
944 static inline int tegra_xusb_init_context(struct tegra_xusb *tegra) in tegra_xusb_init_context() argument
950 static int tegra_xusb_request_firmware(struct tegra_xusb *tegra) in tegra_xusb_request_firmware() argument
956 err = request_firmware(&fw, tegra->soc->firmware, tegra->dev); in tegra_xusb_request_firmware()
958 dev_err(tegra->dev, "failed to request firmware: %d\n", err); in tegra_xusb_request_firmware()
964 tegra->fw.size = le32_to_cpu(header->fwimg_len); in tegra_xusb_request_firmware()
966 tegra->fw.virt = dma_alloc_coherent(tegra->dev, tegra->fw.size, in tegra_xusb_request_firmware()
967 &tegra->fw.phys, GFP_KERNEL); in tegra_xusb_request_firmware()
968 if (!tegra->fw.virt) { in tegra_xusb_request_firmware()
969 dev_err(tegra->dev, "failed to allocate memory for firmware\n"); in tegra_xusb_request_firmware()
974 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_request_firmware()
975 memcpy(tegra->fw.virt, fw->data, tegra->fw.size); in tegra_xusb_request_firmware()
981 static int tegra_xusb_wait_for_falcon(struct tegra_xusb *tegra) in tegra_xusb_wait_for_falcon() argument
988 cap_regs = tegra->regs; in tegra_xusb_wait_for_falcon()
989 op_regs = tegra->regs + HC_LENGTH(readl(&cap_regs->hc_capbase)); in tegra_xusb_wait_for_falcon()
994 dev_err(tegra->dev, "XHCI Controller not ready. Falcon state: 0x%x\n", in tegra_xusb_wait_for_falcon()
995 csb_readl(tegra, XUSB_FALC_CPUCTL)); in tegra_xusb_wait_for_falcon()
1000 static int tegra_xusb_load_firmware_rom(struct tegra_xusb *tegra) in tegra_xusb_load_firmware_rom() argument
1004 struct device *dev = tegra->dev; in tegra_xusb_load_firmware_rom()
1010 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_load_firmware_rom()
1012 if (csb_readl(tegra, XUSB_CSB_MP_ILOAD_BASE_LO) != 0) { in tegra_xusb_load_firmware_rom()
1014 csb_readl(tegra, XUSB_FALC_CPUCTL)); in tegra_xusb_load_firmware_rom()
1019 csb_writel(tegra, tegra->fw.size, XUSB_CSB_MP_ILOAD_ATTR); in tegra_xusb_load_firmware_rom()
1025 address = tegra->fw.phys + sizeof(*header); in tegra_xusb_load_firmware_rom()
1026 csb_writel(tegra, address >> 32, XUSB_CSB_MP_ILOAD_BASE_HI); in tegra_xusb_load_firmware_rom()
1027 csb_writel(tegra, address, XUSB_CSB_MP_ILOAD_BASE_LO); in tegra_xusb_load_firmware_rom()
1030 csb_writel(tegra, APMAP_BOOTPATH, XUSB_CSB_MP_APMAP); in tegra_xusb_load_firmware_rom()
1033 csb_writel(tegra, L2IMEMOP_INVALIDATE_ALL, XUSB_CSB_MP_L2IMEMOP_TRIG); in tegra_xusb_load_firmware_rom()
1049 csb_writel(tegra, value, XUSB_CSB_MP_L2IMEMOP_SIZE); in tegra_xusb_load_firmware_rom()
1052 csb_writel(tegra, L2IMEMOP_LOAD_LOCKED_RESULT, in tegra_xusb_load_firmware_rom()
1056 csb_writel(tegra, code_size_blocks, XUSB_FALC_IMFILLCTL); in tegra_xusb_load_firmware_rom()
1062 csb_writel(tegra, value, XUSB_FALC_IMFILLRNG1); in tegra_xusb_load_firmware_rom()
1064 csb_writel(tegra, 0, XUSB_FALC_DMACTL); in tegra_xusb_load_firmware_rom()
1067 #define tegra_csb_readl(offset) csb_readl(tegra, offset) in tegra_xusb_load_firmware_rom()
1077 csb_writel(tegra, le32_to_cpu(header->boot_codetag), in tegra_xusb_load_firmware_rom()
1081 csb_writel(tegra, CPUCTL_STARTCPU, XUSB_FALC_CPUCTL); in tegra_xusb_load_firmware_rom()
1083 if (tegra_xusb_wait_for_falcon(tegra)) in tegra_xusb_load_firmware_rom()
1093 static u32 tegra_xusb_read_firmware_header(struct tegra_xusb *tegra, u32 offset) in tegra_xusb_read_firmware_header() argument
1102 bar2_writel(tegra, (FW_IOCTL_CFGTBL_READ << FW_IOCTL_TYPE_SHIFT) | offset, in tegra_xusb_read_firmware_header()
1104 return bar2_readl(tegra, XUSB_BAR2_ARU_SMI_ARU_FW_SCRATCH_DATA0); in tegra_xusb_read_firmware_header()
1107 static int tegra_xusb_init_ifr_firmware(struct tegra_xusb *tegra) in tegra_xusb_init_ifr_firmware() argument
1111 if (tegra_xusb_wait_for_falcon(tegra)) in tegra_xusb_init_ifr_firmware()
1115 timestamp = tegra_xusb_read_firmware_header(tegra, offsetof_32(struct tegra_xusb_fw_header, in tegra_xusb_init_ifr_firmware()
1118 dev_info(tegra->dev, "Firmware timestamp: %ptTs UTC\n", ×tamp); in tegra_xusb_init_ifr_firmware()
1123 static int tegra_xusb_load_firmware(struct tegra_xusb *tegra) in tegra_xusb_load_firmware() argument
1125 if (!tegra->soc->firmware) in tegra_xusb_load_firmware()
1126 return tegra_xusb_init_ifr_firmware(tegra); in tegra_xusb_load_firmware()
1128 return tegra_xusb_load_firmware_rom(tegra); in tegra_xusb_load_firmware()
1132 struct tegra_xusb *tegra) in tegra_xusb_powerdomain_remove() argument
1134 if (!tegra->use_genpd) in tegra_xusb_powerdomain_remove()
1137 if (!IS_ERR_OR_NULL(tegra->genpd_dev_ss)) in tegra_xusb_powerdomain_remove()
1138 dev_pm_domain_detach(tegra->genpd_dev_ss, true); in tegra_xusb_powerdomain_remove()
1139 if (!IS_ERR_OR_NULL(tegra->genpd_dev_host)) in tegra_xusb_powerdomain_remove()
1140 dev_pm_domain_detach(tegra->genpd_dev_host, true); in tegra_xusb_powerdomain_remove()
1144 struct tegra_xusb *tegra) in tegra_xusb_powerdomain_init() argument
1148 tegra->genpd_dev_host = dev_pm_domain_attach_by_name(dev, "xusb_host"); in tegra_xusb_powerdomain_init()
1149 if (IS_ERR(tegra->genpd_dev_host)) { in tegra_xusb_powerdomain_init()
1150 err = PTR_ERR(tegra->genpd_dev_host); in tegra_xusb_powerdomain_init()
1155 tegra->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "xusb_ss"); in tegra_xusb_powerdomain_init()
1156 if (IS_ERR(tegra->genpd_dev_ss)) { in tegra_xusb_powerdomain_init()
1157 err = PTR_ERR(tegra->genpd_dev_ss); in tegra_xusb_powerdomain_init()
1162 tegra->use_genpd = true; in tegra_xusb_powerdomain_init()
1167 static int tegra_xusb_unpowergate_partitions(struct tegra_xusb *tegra) in tegra_xusb_unpowergate_partitions() argument
1169 struct device *dev = tegra->dev; in tegra_xusb_unpowergate_partitions()
1172 if (tegra->use_genpd) { in tegra_xusb_unpowergate_partitions()
1173 rc = pm_runtime_resume_and_get(tegra->genpd_dev_ss); in tegra_xusb_unpowergate_partitions()
1179 rc = pm_runtime_resume_and_get(tegra->genpd_dev_host); in tegra_xusb_unpowergate_partitions()
1182 pm_runtime_put_sync(tegra->genpd_dev_ss); in tegra_xusb_unpowergate_partitions()
1187 tegra->ss_clk, in tegra_xusb_unpowergate_partitions()
1188 tegra->ss_rst); in tegra_xusb_unpowergate_partitions()
1195 tegra->host_clk, in tegra_xusb_unpowergate_partitions()
1196 tegra->host_rst); in tegra_xusb_unpowergate_partitions()
1207 static int tegra_xusb_powergate_partitions(struct tegra_xusb *tegra) in tegra_xusb_powergate_partitions() argument
1209 struct device *dev = tegra->dev; in tegra_xusb_powergate_partitions()
1212 if (tegra->use_genpd) { in tegra_xusb_powergate_partitions()
1213 rc = pm_runtime_put_sync(tegra->genpd_dev_host); in tegra_xusb_powergate_partitions()
1219 rc = pm_runtime_put_sync(tegra->genpd_dev_ss); in tegra_xusb_powergate_partitions()
1222 pm_runtime_get_sync(tegra->genpd_dev_host); in tegra_xusb_powergate_partitions()
1236 tegra->host_clk, in tegra_xusb_powergate_partitions()
1237 tegra->host_rst); in tegra_xusb_powergate_partitions()
1245 static int __tegra_xusb_enable_firmware_messages(struct tegra_xusb *tegra) in __tegra_xusb_enable_firmware_messages() argument
1254 err = tegra_xusb_mbox_send(tegra, &msg); in __tegra_xusb_enable_firmware_messages()
1256 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in __tegra_xusb_enable_firmware_messages()
1263 struct tegra_xusb *tegra = data; in tegra_xusb_padctl_irq() local
1265 mutex_lock(&tegra->lock); in tegra_xusb_padctl_irq()
1267 if (tegra->suspended) { in tegra_xusb_padctl_irq()
1268 mutex_unlock(&tegra->lock); in tegra_xusb_padctl_irq()
1272 mutex_unlock(&tegra->lock); in tegra_xusb_padctl_irq()
1274 pm_runtime_resume(tegra->dev); in tegra_xusb_padctl_irq()
1279 static int tegra_xusb_enable_firmware_messages(struct tegra_xusb *tegra) in tegra_xusb_enable_firmware_messages() argument
1283 mutex_lock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1284 err = __tegra_xusb_enable_firmware_messages(tegra); in tegra_xusb_enable_firmware_messages()
1285 mutex_unlock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1290 static void tegra_xhci_set_port_power(struct tegra_xusb *tegra, bool main, in tegra_xhci_set_port_power() argument
1293 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_set_port_power()
1297 u16 wIndex = main ? tegra->otg_usb2_port + 1 : tegra->otg_usb3_port + 1; in tegra_xhci_set_port_power()
1302 dev_dbg(tegra->dev, "%s():%s %s port power\n", __func__, in tegra_xhci_set_port_power()
1321 dev_info(tegra->dev, "failed to %s %s PP %d\n", in tegra_xhci_set_port_power()
1326 static struct phy *tegra_xusb_get_phy(struct tegra_xusb *tegra, char *name, in tegra_xusb_get_phy() argument
1331 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_get_phy()
1332 if (!strncmp(tegra->soc->phy_types[i].name, name, in tegra_xusb_get_phy()
1334 return tegra->phys[phy_count+port]; in tegra_xusb_get_phy()
1336 phy_count += tegra->soc->phy_types[i].num; in tegra_xusb_get_phy()
1344 struct tegra_xusb *tegra = container_of(work, struct tegra_xusb, in tegra_xhci_id_work() local
1346 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_id_work()
1348 struct phy *phy = tegra_xusb_get_phy(tegra, "usb2", in tegra_xhci_id_work()
1349 tegra->otg_usb2_port); in tegra_xhci_id_work()
1353 dev_dbg(tegra->dev, "host mode %s\n", str_on_off(tegra->host_mode)); in tegra_xhci_id_work()
1355 mutex_lock(&tegra->lock); in tegra_xhci_id_work()
1357 if (tegra->host_mode) in tegra_xhci_id_work()
1362 mutex_unlock(&tegra->lock); in tegra_xhci_id_work()
1364 tegra->otg_usb3_port = tegra_xusb_padctl_get_usb3_companion(tegra->padctl, in tegra_xhci_id_work()
1365 tegra->otg_usb2_port); in tegra_xhci_id_work()
1367 if (tegra->host_mode) { in tegra_xhci_id_work()
1369 if (tegra->otg_usb3_port >= 0) { in tegra_xhci_id_work()
1370 if (tegra->soc->otg_reset_sspi) { in tegra_xhci_id_work()
1374 0, tegra->otg_usb3_port+1, in tegra_xhci_id_work()
1377 tegra_xhci_set_port_power(tegra, false, in tegra_xhci_id_work()
1382 msg.data = tegra->otg_usb3_port+1; in tegra_xhci_id_work()
1384 ret = tegra_xusb_mbox_send(tegra, &msg); in tegra_xhci_id_work()
1386 dev_info(tegra->dev, in tegra_xhci_id_work()
1392 tegra_xhci_set_port_power(tegra, false, true); in tegra_xhci_id_work()
1395 tegra_xhci_set_port_power(tegra, true, true); in tegra_xhci_id_work()
1398 if (tegra->otg_usb3_port >= 0) in tegra_xhci_id_work()
1399 tegra_xhci_set_port_power(tegra, false, false); in tegra_xhci_id_work()
1401 tegra_xhci_set_port_power(tegra, true, false); in tegra_xhci_id_work()
1406 static bool is_usb2_otg_phy(struct tegra_xusb *tegra, unsigned int index) in is_usb2_otg_phy() argument
1408 return (tegra->usbphy[index] != NULL); in is_usb2_otg_phy()
1411 static bool is_usb3_otg_phy(struct tegra_xusb *tegra, unsigned int index) in is_usb3_otg_phy() argument
1413 struct tegra_xusb_padctl *padctl = tegra->padctl; in is_usb3_otg_phy()
1417 for (i = 0; i < tegra->num_usb_phys; i++) { in is_usb3_otg_phy()
1418 if (is_usb2_otg_phy(tegra, i)) { in is_usb3_otg_phy()
1428 static bool is_host_mode_phy(struct tegra_xusb *tegra, unsigned int phy_type, unsigned int index) in is_host_mode_phy() argument
1430 if (strcmp(tegra->soc->phy_types[phy_type].name, "hsic") == 0) in is_host_mode_phy()
1433 if (strcmp(tegra->soc->phy_types[phy_type].name, "usb2") == 0) { in is_host_mode_phy()
1434 if (is_usb2_otg_phy(tegra, index)) in is_host_mode_phy()
1435 return ((index == tegra->otg_usb2_port) && tegra->host_mode); in is_host_mode_phy()
1440 if (strcmp(tegra->soc->phy_types[phy_type].name, "usb3") == 0) { in is_host_mode_phy()
1441 if (is_usb3_otg_phy(tegra, index)) in is_host_mode_phy()
1442 return ((index == tegra->otg_usb3_port) && tegra->host_mode); in is_host_mode_phy()
1451 static int tegra_xusb_get_usb2_port(struct tegra_xusb *tegra, in tegra_xusb_get_usb2_port() argument
1456 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_get_usb2_port()
1457 if (tegra->usbphy[i] && usbphy == tegra->usbphy[i]) in tegra_xusb_get_usb2_port()
1467 struct tegra_xusb *tegra = container_of(nb, struct tegra_xusb, in tegra_xhci_id_notify() local
1471 dev_dbg(tegra->dev, "%s(): action is %d", __func__, usbphy->last_event); in tegra_xhci_id_notify()
1473 if ((tegra->host_mode && usbphy->last_event == USB_EVENT_ID) || in tegra_xhci_id_notify()
1474 (!tegra->host_mode && usbphy->last_event != USB_EVENT_ID)) { in tegra_xhci_id_notify()
1475 dev_dbg(tegra->dev, "Same role(%d) received. Ignore", in tegra_xhci_id_notify()
1476 tegra->host_mode); in tegra_xhci_id_notify()
1480 tegra->otg_usb2_port = tegra_xusb_get_usb2_port(tegra, usbphy); in tegra_xhci_id_notify()
1482 tegra->host_mode = (usbphy->last_event == USB_EVENT_ID) ? true : false; in tegra_xhci_id_notify()
1484 schedule_work(&tegra->id_work); in tegra_xhci_id_notify()
1489 static int tegra_xusb_init_usb_phy(struct tegra_xusb *tegra) in tegra_xusb_init_usb_phy() argument
1493 tegra->usbphy = devm_kcalloc(tegra->dev, tegra->num_usb_phys, in tegra_xusb_init_usb_phy()
1494 sizeof(*tegra->usbphy), GFP_KERNEL); in tegra_xusb_init_usb_phy()
1495 if (!tegra->usbphy) in tegra_xusb_init_usb_phy()
1498 INIT_WORK(&tegra->id_work, tegra_xhci_id_work); in tegra_xusb_init_usb_phy()
1499 tegra->id_nb.notifier_call = tegra_xhci_id_notify; in tegra_xusb_init_usb_phy()
1500 tegra->otg_usb2_port = -EINVAL; in tegra_xusb_init_usb_phy()
1501 tegra->otg_usb3_port = -EINVAL; in tegra_xusb_init_usb_phy()
1503 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_init_usb_phy()
1504 struct phy *phy = tegra_xusb_get_phy(tegra, "usb2", i); in tegra_xusb_init_usb_phy()
1509 tegra->usbphy[i] = devm_usb_get_phy_by_node(tegra->dev, in tegra_xusb_init_usb_phy()
1511 &tegra->id_nb); in tegra_xusb_init_usb_phy()
1512 if (!IS_ERR(tegra->usbphy[i])) { in tegra_xusb_init_usb_phy()
1513 dev_dbg(tegra->dev, "usbphy-%d registered", i); in tegra_xusb_init_usb_phy()
1514 otg_set_host(tegra->usbphy[i]->otg, &tegra->hcd->self); in tegra_xusb_init_usb_phy()
1519 tegra->usbphy[i] = NULL; in tegra_xusb_init_usb_phy()
1526 static void tegra_xusb_deinit_usb_phy(struct tegra_xusb *tegra) in tegra_xusb_deinit_usb_phy() argument
1530 cancel_work_sync(&tegra->id_work); in tegra_xusb_deinit_usb_phy()
1532 for (i = 0; i < tegra->num_usb_phys; i++) in tegra_xusb_deinit_usb_phy()
1533 if (tegra->usbphy[i]) in tegra_xusb_deinit_usb_phy()
1534 otg_set_host(tegra->usbphy[i]->otg, NULL); in tegra_xusb_deinit_usb_phy()
1539 struct tegra_xusb *tegra; in tegra_xusb_probe() local
1549 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_xusb_probe()
1550 if (!tegra) in tegra_xusb_probe()
1553 tegra->soc = of_device_get_match_data(&pdev->dev); in tegra_xusb_probe()
1554 mutex_init(&tegra->lock); in tegra_xusb_probe()
1555 tegra->dev = &pdev->dev; in tegra_xusb_probe()
1557 err = tegra_xusb_init_context(tegra); in tegra_xusb_probe()
1561 tegra->regs = devm_platform_get_and_ioremap_resource(pdev, 0, ®s); in tegra_xusb_probe()
1562 if (IS_ERR(tegra->regs)) in tegra_xusb_probe()
1563 return PTR_ERR(tegra->regs); in tegra_xusb_probe()
1565 tegra->fpci_base = devm_platform_ioremap_resource(pdev, 1); in tegra_xusb_probe()
1566 if (IS_ERR(tegra->fpci_base)) in tegra_xusb_probe()
1567 return PTR_ERR(tegra->fpci_base); in tegra_xusb_probe()
1569 if (tegra->soc->has_ipfs) { in tegra_xusb_probe()
1570 tegra->ipfs_base = devm_platform_ioremap_resource(pdev, 2); in tegra_xusb_probe()
1571 if (IS_ERR(tegra->ipfs_base)) in tegra_xusb_probe()
1572 return PTR_ERR(tegra->ipfs_base); in tegra_xusb_probe()
1573 } else if (tegra->soc->has_bar2) { in tegra_xusb_probe()
1574 tegra->bar2_base = devm_platform_get_and_ioremap_resource(pdev, 2, &tegra->bar2); in tegra_xusb_probe()
1575 if (IS_ERR(tegra->bar2_base)) in tegra_xusb_probe()
1576 return PTR_ERR(tegra->bar2_base); in tegra_xusb_probe()
1579 tegra->xhci_irq = platform_get_irq(pdev, 0); in tegra_xusb_probe()
1580 if (tegra->xhci_irq < 0) in tegra_xusb_probe()
1581 return tegra->xhci_irq; in tegra_xusb_probe()
1583 tegra->mbox_irq = platform_get_irq(pdev, 1); in tegra_xusb_probe()
1584 if (tegra->mbox_irq < 0) in tegra_xusb_probe()
1585 return tegra->mbox_irq; in tegra_xusb_probe()
1587 tegra->padctl = tegra_xusb_padctl_get(&pdev->dev); in tegra_xusb_probe()
1588 if (IS_ERR(tegra->padctl)) in tegra_xusb_probe()
1589 return PTR_ERR(tegra->padctl); in tegra_xusb_probe()
1597 tegra->padctl_irq = of_irq_get(np, 0); in tegra_xusb_probe()
1598 if (tegra->padctl_irq == -EPROBE_DEFER) { in tegra_xusb_probe()
1599 err = tegra->padctl_irq; in tegra_xusb_probe()
1601 } else if (tegra->padctl_irq <= 0) { in tegra_xusb_probe()
1603 tegra->padctl_irq = 0; in tegra_xusb_probe()
1608 tegra->host_clk = devm_clk_get(&pdev->dev, "xusb_host"); in tegra_xusb_probe()
1609 if (IS_ERR(tegra->host_clk)) { in tegra_xusb_probe()
1610 err = PTR_ERR(tegra->host_clk); in tegra_xusb_probe()
1615 tegra->falcon_clk = devm_clk_get(&pdev->dev, "xusb_falcon_src"); in tegra_xusb_probe()
1616 if (IS_ERR(tegra->falcon_clk)) { in tegra_xusb_probe()
1617 err = PTR_ERR(tegra->falcon_clk); in tegra_xusb_probe()
1622 tegra->ss_clk = devm_clk_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1623 if (IS_ERR(tegra->ss_clk)) { in tegra_xusb_probe()
1624 err = PTR_ERR(tegra->ss_clk); in tegra_xusb_probe()
1629 tegra->ss_src_clk = devm_clk_get(&pdev->dev, "xusb_ss_src"); in tegra_xusb_probe()
1630 if (IS_ERR(tegra->ss_src_clk)) { in tegra_xusb_probe()
1631 err = PTR_ERR(tegra->ss_src_clk); in tegra_xusb_probe()
1636 tegra->hs_src_clk = devm_clk_get(&pdev->dev, "xusb_hs_src"); in tegra_xusb_probe()
1637 if (IS_ERR(tegra->hs_src_clk)) { in tegra_xusb_probe()
1638 err = PTR_ERR(tegra->hs_src_clk); in tegra_xusb_probe()
1643 tegra->fs_src_clk = devm_clk_get(&pdev->dev, "xusb_fs_src"); in tegra_xusb_probe()
1644 if (IS_ERR(tegra->fs_src_clk)) { in tegra_xusb_probe()
1645 err = PTR_ERR(tegra->fs_src_clk); in tegra_xusb_probe()
1650 tegra->pll_u_480m = devm_clk_get(&pdev->dev, "pll_u_480m"); in tegra_xusb_probe()
1651 if (IS_ERR(tegra->pll_u_480m)) { in tegra_xusb_probe()
1652 err = PTR_ERR(tegra->pll_u_480m); in tegra_xusb_probe()
1657 tegra->clk_m = devm_clk_get(&pdev->dev, "clk_m"); in tegra_xusb_probe()
1658 if (IS_ERR(tegra->clk_m)) { in tegra_xusb_probe()
1659 err = PTR_ERR(tegra->clk_m); in tegra_xusb_probe()
1664 tegra->pll_e = devm_clk_get(&pdev->dev, "pll_e"); in tegra_xusb_probe()
1665 if (IS_ERR(tegra->pll_e)) { in tegra_xusb_probe()
1666 err = PTR_ERR(tegra->pll_e); in tegra_xusb_probe()
1672 tegra->host_rst = devm_reset_control_get(&pdev->dev, in tegra_xusb_probe()
1674 if (IS_ERR(tegra->host_rst)) { in tegra_xusb_probe()
1675 err = PTR_ERR(tegra->host_rst); in tegra_xusb_probe()
1681 tegra->ss_rst = devm_reset_control_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1682 if (IS_ERR(tegra->ss_rst)) { in tegra_xusb_probe()
1683 err = PTR_ERR(tegra->ss_rst); in tegra_xusb_probe()
1689 err = tegra_xusb_powerdomain_init(&pdev->dev, tegra); in tegra_xusb_probe()
1694 tegra->supplies = devm_kcalloc(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1695 sizeof(*tegra->supplies), GFP_KERNEL); in tegra_xusb_probe()
1696 if (!tegra->supplies) { in tegra_xusb_probe()
1701 regulator_bulk_set_supply_names(tegra->supplies, in tegra_xusb_probe()
1702 tegra->soc->supply_names, in tegra_xusb_probe()
1703 tegra->soc->num_supplies); in tegra_xusb_probe()
1705 err = devm_regulator_bulk_get(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1706 tegra->supplies); in tegra_xusb_probe()
1712 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1713 if (!strncmp(tegra->soc->phy_types[i].name, "usb2", 4)) in tegra_xusb_probe()
1714 tegra->num_usb_phys = tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1715 tegra->num_phys += tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1718 tegra->phys = devm_kcalloc(&pdev->dev, tegra->num_phys, in tegra_xusb_probe()
1719 sizeof(*tegra->phys), GFP_KERNEL); in tegra_xusb_probe()
1720 if (!tegra->phys) { in tegra_xusb_probe()
1725 for (i = 0, k = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1728 for (j = 0; j < tegra->soc->phy_types[i].num; j++) { in tegra_xusb_probe()
1730 tegra->soc->phy_types[i].name, j); in tegra_xusb_probe()
1741 tegra->phys[k++] = phy; in tegra_xusb_probe()
1745 tegra->hcd = usb_create_hcd(&tegra_xhci_hc_driver, &pdev->dev, in tegra_xusb_probe()
1747 if (!tegra->hcd) { in tegra_xusb_probe()
1752 tegra->hcd->skip_phy_initialization = 1; in tegra_xusb_probe()
1753 tegra->hcd->regs = tegra->regs; in tegra_xusb_probe()
1754 tegra->hcd->rsrc_start = regs->start; in tegra_xusb_probe()
1755 tegra->hcd->rsrc_len = resource_size(regs); in tegra_xusb_probe()
1761 platform_set_drvdata(pdev, tegra); in tegra_xusb_probe()
1763 err = tegra_xusb_clk_enable(tegra); in tegra_xusb_probe()
1765 dev_err(tegra->dev, "failed to enable clocks: %d\n", err); in tegra_xusb_probe()
1769 err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_probe()
1771 dev_err(tegra->dev, "failed to enable regulators: %d\n", err); in tegra_xusb_probe()
1775 err = tegra_xusb_phy_enable(tegra); in tegra_xusb_probe()
1785 err = dma_set_mask_and_coherent(tegra->dev, DMA_BIT_MASK(40)); in tegra_xusb_probe()
1791 if (tegra->soc->firmware) { in tegra_xusb_probe()
1792 err = tegra_xusb_request_firmware(tegra); in tegra_xusb_probe()
1800 err = tegra_xusb_unpowergate_partitions(tegra); in tegra_xusb_probe()
1804 tegra_xusb_config(tegra); in tegra_xusb_probe()
1806 err = tegra_xusb_load_firmware(tegra); in tegra_xusb_probe()
1812 err = usb_add_hcd(tegra->hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1818 device_wakeup_enable(tegra->hcd->self.controller); in tegra_xusb_probe()
1820 xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_probe()
1825 tegra->hcd); in tegra_xusb_probe()
1835 err = usb_add_hcd(xhci->shared_hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1841 err = devm_request_threaded_irq(&pdev->dev, tegra->mbox_irq, in tegra_xusb_probe()
1844 dev_name(&pdev->dev), tegra); in tegra_xusb_probe()
1850 if (tegra->padctl_irq) { in tegra_xusb_probe()
1851 err = devm_request_threaded_irq(&pdev->dev, tegra->padctl_irq, in tegra_xusb_probe()
1854 tegra); in tegra_xusb_probe()
1861 err = tegra_xusb_enable_firmware_messages(tegra); in tegra_xusb_probe()
1867 err = tegra_xusb_init_usb_phy(tegra); in tegra_xusb_probe()
1874 device_init_wakeup(&tegra->hcd->self.root_hub->dev, true); in tegra_xusb_probe()
1877 pm_runtime_use_autosuspend(tegra->dev); in tegra_xusb_probe()
1878 pm_runtime_set_autosuspend_delay(tegra->dev, 2000); in tegra_xusb_probe()
1879 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_probe()
1880 pm_runtime_set_active(tegra->dev); in tegra_xusb_probe()
1882 if (tegra->padctl_irq) { in tegra_xusb_probe()
1883 device_init_wakeup(tegra->dev, true); in tegra_xusb_probe()
1884 pm_runtime_enable(tegra->dev); in tegra_xusb_probe()
1894 usb_remove_hcd(tegra->hcd); in tegra_xusb_probe()
1896 tegra_xusb_powergate_partitions(tegra); in tegra_xusb_probe()
1898 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_probe()
1899 tegra->fw.phys); in tegra_xusb_probe()
1901 tegra_xusb_phy_disable(tegra); in tegra_xusb_probe()
1903 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_probe()
1905 tegra_xusb_clk_disable(tegra); in tegra_xusb_probe()
1907 usb_put_hcd(tegra->hcd); in tegra_xusb_probe()
1909 tegra_xusb_powerdomain_remove(&pdev->dev, tegra); in tegra_xusb_probe()
1912 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_probe()
1916 static void tegra_xusb_disable(struct tegra_xusb *tegra) in tegra_xusb_disable() argument
1918 tegra_xusb_powergate_partitions(tegra); in tegra_xusb_disable()
1919 tegra_xusb_powerdomain_remove(tegra->dev, tegra); in tegra_xusb_disable()
1920 tegra_xusb_phy_disable(tegra); in tegra_xusb_disable()
1921 tegra_xusb_clk_disable(tegra); in tegra_xusb_disable()
1922 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_disable()
1927 struct tegra_xusb *tegra = platform_get_drvdata(pdev); in tegra_xusb_remove() local
1928 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_remove()
1930 tegra_xusb_deinit_usb_phy(tegra); in tegra_xusb_remove()
1936 usb_remove_hcd(tegra->hcd); in tegra_xusb_remove()
1937 usb_put_hcd(tegra->hcd); in tegra_xusb_remove()
1939 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_remove()
1940 tegra->fw.phys); in tegra_xusb_remove()
1942 if (tegra->padctl_irq) in tegra_xusb_remove()
1947 tegra_xusb_disable(tegra); in tegra_xusb_remove()
1948 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_remove()
1953 struct tegra_xusb *tegra = platform_get_drvdata(pdev); in tegra_xusb_shutdown() local
1956 disable_irq(tegra->xhci_irq); in tegra_xusb_shutdown()
1957 xhci_shutdown(tegra->hcd); in tegra_xusb_shutdown()
1958 tegra_xusb_disable(tegra); in tegra_xusb_shutdown()
1983 static int tegra_xusb_check_ports(struct tegra_xusb *tegra) in tegra_xusb_check_ports() argument
1985 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_check_ports()
2008 static void tegra_xusb_save_context(struct tegra_xusb *tegra) in tegra_xusb_save_context() argument
2010 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_save_context()
2011 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_save_context()
2016 ctx->ipfs[i] = ipfs_readl(tegra, soc->ipfs.offsets[i]); in tegra_xusb_save_context()
2021 ctx->fpci[i] = fpci_readl(tegra, soc->fpci.offsets[i]); in tegra_xusb_save_context()
2025 static void tegra_xusb_restore_context(struct tegra_xusb *tegra) in tegra_xusb_restore_context() argument
2027 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_restore_context()
2028 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_restore_context()
2033 fpci_writel(tegra, ctx->fpci[i], soc->fpci.offsets[i]); in tegra_xusb_restore_context()
2038 ipfs_writel(tegra, ctx->ipfs[i], soc->ipfs.offsets[i]); in tegra_xusb_restore_context()
2042 static enum usb_device_speed tegra_xhci_portsc_to_speed(struct tegra_xusb *tegra, u32 portsc) in tegra_xhci_portsc_to_speed() argument
2059 static void tegra_xhci_enable_phy_sleepwalk_wake(struct tegra_xusb *tegra) in tegra_xhci_enable_phy_sleepwalk_wake() argument
2061 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_enable_phy_sleepwalk_wake()
2062 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_enable_phy_sleepwalk_wake()
2070 for (i = 0, k = 0; i < tegra->soc->num_types; i++) { in tegra_xhci_enable_phy_sleepwalk_wake()
2071 if (strcmp(tegra->soc->phy_types[i].name, "usb3") == 0) in tegra_xhci_enable_phy_sleepwalk_wake()
2076 if (strcmp(tegra->soc->phy_types[i].name, "hsic") == 0) in tegra_xhci_enable_phy_sleepwalk_wake()
2077 offset = tegra->soc->ports.usb2.count; in tegra_xhci_enable_phy_sleepwalk_wake()
2081 for (j = 0; j < tegra->soc->phy_types[i].num; j++) { in tegra_xhci_enable_phy_sleepwalk_wake()
2082 phy = tegra->phys[k++]; in tegra_xhci_enable_phy_sleepwalk_wake()
2092 if (!is_host_mode_phy(tegra, i, j)) in tegra_xhci_enable_phy_sleepwalk_wake()
2096 speed = tegra_xhci_portsc_to_speed(tegra, portsc); in tegra_xhci_enable_phy_sleepwalk_wake()
2103 static void tegra_xhci_disable_phy_wake(struct tegra_xusb *tegra) in tegra_xhci_disable_phy_wake() argument
2105 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_disable_phy_wake()
2108 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xhci_disable_phy_wake()
2109 struct phy *phy = tegra_xusb_get_phy(tegra, "usb2", i); in tegra_xhci_disable_phy_wake()
2118 for (i = 0; i < tegra->num_phys; i++) { in tegra_xhci_disable_phy_wake()
2119 if (!tegra->phys[i]) in tegra_xhci_disable_phy_wake()
2122 if (tegra_xusb_padctl_remote_wake_detected(padctl, tegra->phys[i])) in tegra_xhci_disable_phy_wake()
2123 dev_dbg(tegra->dev, "%pOF remote wake detected\n", in tegra_xhci_disable_phy_wake()
2124 tegra->phys[i]->dev.of_node); in tegra_xhci_disable_phy_wake()
2126 tegra_xusb_padctl_disable_phy_wake(padctl, tegra->phys[i]); in tegra_xhci_disable_phy_wake()
2130 static void tegra_xhci_disable_phy_sleepwalk(struct tegra_xusb *tegra) in tegra_xhci_disable_phy_sleepwalk() argument
2132 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_disable_phy_sleepwalk()
2135 for (i = 0; i < tegra->num_phys; i++) { in tegra_xhci_disable_phy_sleepwalk()
2136 if (!tegra->phys[i]) in tegra_xhci_disable_phy_sleepwalk()
2139 tegra_xusb_padctl_disable_phy_sleepwalk(padctl, tegra->phys[i]); in tegra_xhci_disable_phy_sleepwalk()
2143 static void tegra_xhci_program_utmi_power_lp0_exit(struct tegra_xusb *tegra) in tegra_xhci_program_utmi_power_lp0_exit() argument
2148 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xhci_program_utmi_power_lp0_exit()
2149 if (strcmp(tegra->soc->phy_types[i].name, "usb2") == 0) in tegra_xhci_program_utmi_power_lp0_exit()
2153 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xhci_program_utmi_power_lp0_exit()
2154 if (!is_host_mode_phy(tegra, index_to_usb2, i)) in tegra_xhci_program_utmi_power_lp0_exit()
2157 phy = tegra_xusb_get_phy(tegra, "usb2", i); in tegra_xhci_program_utmi_power_lp0_exit()
2158 if (tegra->lp0_utmi_pad_mask & BIT(i)) in tegra_xhci_program_utmi_power_lp0_exit()
2165 static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool runtime) in tegra_xusb_enter_elpg() argument
2167 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_enter_elpg()
2168 struct device *dev = tegra->dev; in tegra_xusb_enter_elpg()
2181 err = tegra_xusb_check_ports(tegra); in tegra_xusb_enter_elpg()
2183 dev_err(tegra->dev, "not all ports suspended: %d\n", err); in tegra_xusb_enter_elpg()
2191 tegra->lp0_utmi_pad_mask &= ~BIT(i); in tegra_xusb_enter_elpg()
2193 tegra->lp0_utmi_pad_mask |= BIT(i); in tegra_xusb_enter_elpg()
2198 dev_err(tegra->dev, "failed to suspend XHCI: %d\n", err); in tegra_xusb_enter_elpg()
2202 tegra_xusb_save_context(tegra); in tegra_xusb_enter_elpg()
2205 tegra_xhci_enable_phy_sleepwalk_wake(tegra); in tegra_xusb_enter_elpg()
2207 tegra_xusb_powergate_partitions(tegra); in tegra_xusb_enter_elpg()
2209 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_enter_elpg()
2210 if (!tegra->phys[i]) in tegra_xusb_enter_elpg()
2213 phy_power_off(tegra->phys[i]); in tegra_xusb_enter_elpg()
2215 phy_exit(tegra->phys[i]); in tegra_xusb_enter_elpg()
2218 tegra_xusb_clk_disable(tegra); in tegra_xusb_enter_elpg()
2222 dev_dbg(tegra->dev, "entering ELPG done\n"); in tegra_xusb_enter_elpg()
2228 dev_dbg(tegra->dev, "entering ELPG failed\n"); in tegra_xusb_enter_elpg()
2229 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_enter_elpg()
2235 static int tegra_xusb_exit_elpg(struct tegra_xusb *tegra, bool runtime) in tegra_xusb_exit_elpg() argument
2237 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_exit_elpg()
2238 struct device *dev = tegra->dev; in tegra_xusb_exit_elpg()
2245 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_exit_elpg()
2247 err = tegra_xusb_clk_enable(tegra); in tegra_xusb_exit_elpg()
2249 dev_err(tegra->dev, "failed to enable clocks: %d\n", err); in tegra_xusb_exit_elpg()
2253 err = tegra_xusb_unpowergate_partitions(tegra); in tegra_xusb_exit_elpg()
2258 tegra_xhci_disable_phy_wake(tegra); in tegra_xusb_exit_elpg()
2260 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_exit_elpg()
2261 if (!tegra->phys[i]) in tegra_xusb_exit_elpg()
2265 phy_init(tegra->phys[i]); in tegra_xusb_exit_elpg()
2267 phy_power_on(tegra->phys[i]); in tegra_xusb_exit_elpg()
2269 if (tegra->suspended) in tegra_xusb_exit_elpg()
2270 tegra_xhci_program_utmi_power_lp0_exit(tegra); in tegra_xusb_exit_elpg()
2272 tegra_xusb_config(tegra); in tegra_xusb_exit_elpg()
2273 tegra_xusb_restore_context(tegra); in tegra_xusb_exit_elpg()
2275 err = tegra_xusb_load_firmware(tegra); in tegra_xusb_exit_elpg()
2277 dev_err(tegra->dev, "failed to load firmware: %d\n", err); in tegra_xusb_exit_elpg()
2281 err = __tegra_xusb_enable_firmware_messages(tegra); in tegra_xusb_exit_elpg()
2283 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in tegra_xusb_exit_elpg()
2288 tegra_xhci_disable_phy_sleepwalk(tegra); in tegra_xusb_exit_elpg()
2292 dev_err(tegra->dev, "failed to resume XHCI: %d\n", err); in tegra_xusb_exit_elpg()
2303 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_exit_elpg()
2304 if (!tegra->phys[i]) in tegra_xusb_exit_elpg()
2307 phy_power_off(tegra->phys[i]); in tegra_xusb_exit_elpg()
2309 phy_exit(tegra->phys[i]); in tegra_xusb_exit_elpg()
2311 tegra_xusb_powergate_partitions(tegra); in tegra_xusb_exit_elpg()
2313 tegra_xusb_clk_disable(tegra); in tegra_xusb_exit_elpg()
2325 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xusb_suspend() local
2328 synchronize_irq(tegra->mbox_irq); in tegra_xusb_suspend()
2330 mutex_lock(&tegra->lock); in tegra_xusb_suspend()
2333 err = tegra_xusb_exit_elpg(tegra, true); in tegra_xusb_suspend()
2338 err = tegra_xusb_enter_elpg(tegra, false); in tegra_xusb_suspend()
2351 tegra->suspended = true; in tegra_xusb_suspend()
2355 if (enable_irq_wake(tegra->padctl_irq)) in tegra_xusb_suspend()
2360 mutex_unlock(&tegra->lock); in tegra_xusb_suspend()
2367 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xusb_resume() local
2370 mutex_lock(&tegra->lock); in tegra_xusb_resume()
2372 if (!tegra->suspended) { in tegra_xusb_resume()
2373 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2377 err = tegra_xusb_exit_elpg(tegra, false); in tegra_xusb_resume()
2379 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2384 if (disable_irq_wake(tegra->padctl_irq)) in tegra_xusb_resume()
2387 tegra->suspended = false; in tegra_xusb_resume()
2388 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2398 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xusb_runtime_suspend() local
2401 synchronize_irq(tegra->mbox_irq); in tegra_xusb_runtime_suspend()
2402 mutex_lock(&tegra->lock); in tegra_xusb_runtime_suspend()
2403 ret = tegra_xusb_enter_elpg(tegra, true); in tegra_xusb_runtime_suspend()
2404 mutex_unlock(&tegra->lock); in tegra_xusb_runtime_suspend()
2411 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xusb_runtime_resume() local
2414 mutex_lock(&tegra->lock); in tegra_xusb_runtime_resume()
2415 err = tegra_xusb_exit_elpg(tegra, true); in tegra_xusb_runtime_resume()
2416 mutex_unlock(&tegra->lock); in tegra_xusb_runtime_resume()
2671 .name = "tegra-xusb",
2679 struct tegra_xusb *tegra = dev_get_drvdata(dev); in tegra_xhci_quirks() local
2681 if (tegra && tegra->soc->lpm_support) in tegra_xhci_quirks()
2693 struct tegra_xusb *tegra = dev_get_drvdata(hcd->self.controller); in tegra_xhci_hub_control() local
2715 tegra_xusb_get_phy(tegra, "usb2", (int) i)); in tegra_xhci_hub_control()
2720 phy = tegra_xusb_get_phy(tegra, "usb2", port); in tegra_xhci_hub_control()
2785 MODULE_DESCRIPTION("NVIDIA Tegra XUSB xHCI host-controller driver");