Lines Matching +full:tegra210 +full:- +full:pmc

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved.
11 #include <linux/dma-mapping.h>
32 #include <soc/tegra/pmc.h>
321 return readl(tegra->fpci_base + offset); in fpci_readl()
327 writel(value, tegra->fpci_base + offset); in fpci_writel()
332 return readl(tegra->ipfs_base + offset); in ipfs_readl()
338 writel(value, tegra->ipfs_base + offset); in ipfs_writel()
343 return readl(tegra->bar2_base + offset); in bar2_readl()
349 writel(value, tegra->bar2_base + offset); in bar2_writel()
354 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in csb_readl()
356 return ops->csb_reg_readl(tegra, offset); in csb_readl()
362 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in csb_writel()
364 ops->csb_reg_writel(tegra, value, offset); in csb_writel()
411 struct clk *clk = tegra->ss_src_clk; in tegra_xusb_set_ss_clk()
425 new_parent_rate = clk_get_rate(tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
432 err = clk_set_parent(clk, tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
448 err = clk_set_parent(clk, tegra->clk_m); in tegra_xusb_set_ss_clk()
459 dev_err(tegra->dev, "Invalid SS rate: %lu Hz\n", rate); in tegra_xusb_set_ss_clk()
460 return -EINVAL; in tegra_xusb_set_ss_clk()
464 dev_err(tegra->dev, "SS clock doesn't match requested rate\n"); in tegra_xusb_set_ss_clk()
465 return -EINVAL; in tegra_xusb_set_ss_clk()
474 return (value >> start) & ((1 << count) - 1); in extract_field()
512 return (msg->cmd & CMD_TYPE_MASK) << CMD_TYPE_SHIFT | in tegra_xusb_mbox_pack()
513 (msg->data & CMD_DATA_MASK) << CMD_DATA_SHIFT; in tegra_xusb_mbox_pack()
518 msg->cmd = (value >> CMD_TYPE_SHIFT) & CMD_TYPE_MASK; in tegra_xusb_mbox_unpack()
519 msg->data = (value >> CMD_DATA_SHIFT) & CMD_DATA_MASK; in tegra_xusb_mbox_unpack()
538 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_send()
546 if (!(msg->cmd == MBOX_CMD_ACK || msg->cmd == MBOX_CMD_NAK)) { in tegra_xusb_mbox_send()
547 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
549 dev_err(tegra->dev, "mailbox is busy\n"); in tegra_xusb_mbox_send()
550 return -EBUSY; in tegra_xusb_mbox_send()
553 ops->mbox_reg_writel(tegra, MBOX_OWNER_SW, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
555 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
557 dev_err(tegra->dev, "failed to acquire mailbox\n"); in tegra_xusb_mbox_send()
558 return -EBUSY; in tegra_xusb_mbox_send()
565 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.data_in); in tegra_xusb_mbox_send()
567 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
569 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
575 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
583 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
586 return -ETIMEDOUT; in tegra_xusb_mbox_send()
595 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_irq()
599 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.smi_intr); in tegra_xusb_mbox_irq()
600 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.smi_intr); in tegra_xusb_mbox_irq()
603 dev_err(tegra->dev, "controller firmware hang\n"); in tegra_xusb_mbox_irq()
611 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xusb_mbox_handle()
612 const struct tegra_xusb_soc *soc = tegra->soc; in tegra_xusb_mbox_handle()
613 struct device *dev = tegra->dev; in tegra_xusb_mbox_handle()
622 switch (msg->cmd) { in tegra_xusb_mbox_handle()
625 rsp.data = clk_get_rate(tegra->falcon_clk) / 1000; in tegra_xusb_mbox_handle()
626 if (rsp.data != msg->data) in tegra_xusb_mbox_handle()
635 if (tegra->soc->scale_ss_clock) { in tegra_xusb_mbox_handle()
636 err = tegra_xusb_set_ss_clk(tegra, msg->data * 1000); in tegra_xusb_mbox_handle()
642 rsp.data = clk_get_rate(tegra->ss_src_clk) / 1000; in tegra_xusb_mbox_handle()
645 rsp.data = msg->data; in tegra_xusb_mbox_handle()
659 err = tegra_xusb_padctl_usb3_save_context(padctl, msg->data); in tegra_xusb_mbox_handle()
662 msg->data, err); in tegra_xusb_mbox_handle()
668 rsp.data = msg->data; in tegra_xusb_mbox_handle()
673 if (msg->cmd == MBOX_CMD_STOP_HSIC_IDLE) in tegra_xusb_mbox_handle()
678 mask = extract_field(msg->data, 1 + soc->ports.hsic.offset, in tegra_xusb_mbox_handle()
679 soc->ports.hsic.count); in tegra_xusb_mbox_handle()
696 rsp.data = msg->data; in tegra_xusb_mbox_handle()
701 if (msg->cmd == MBOX_CMD_DISABLE_SS_LFPS_DETECTION) in tegra_xusb_mbox_handle()
706 mask = extract_field(msg->data, 1 + soc->ports.usb3.offset, in tegra_xusb_mbox_handle()
707 soc->ports.usb3.count); in tegra_xusb_mbox_handle()
709 for_each_set_bit(port, &mask, soc->ports.usb3.count) { in tegra_xusb_mbox_handle()
733 rsp.data = msg->data; in tegra_xusb_mbox_handle()
737 dev_warn(dev, "unknown message: %#x\n", msg->cmd); in tegra_xusb_mbox_handle()
753 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_thread()
757 mutex_lock(&tegra->lock); in tegra_xusb_mbox_thread()
759 if (pm_runtime_suspended(tegra->dev) || tegra->suspended) in tegra_xusb_mbox_thread()
762 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.data_out); in tegra_xusb_mbox_thread()
765 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
767 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
771 ops->mbox_reg_writel(tegra, MBOX_OWNER_NONE, tegra->soc->mbox.owner); in tegra_xusb_mbox_thread()
776 mutex_unlock(&tegra->lock); in tegra_xusb_mbox_thread()
782 u32 regs = tegra->hcd->rsrc_start; in tegra_xusb_config()
785 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
800 if (tegra->bar2) { in tegra_xusb_config()
803 value |= tegra->bar2->start & in tegra_xusb_config()
815 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
830 err = clk_prepare_enable(tegra->pll_e); in tegra_xusb_clk_enable()
834 err = clk_prepare_enable(tegra->host_clk); in tegra_xusb_clk_enable()
838 err = clk_prepare_enable(tegra->ss_clk); in tegra_xusb_clk_enable()
842 err = clk_prepare_enable(tegra->falcon_clk); in tegra_xusb_clk_enable()
846 err = clk_prepare_enable(tegra->fs_src_clk); in tegra_xusb_clk_enable()
850 err = clk_prepare_enable(tegra->hs_src_clk); in tegra_xusb_clk_enable()
854 if (tegra->soc->scale_ss_clock) { in tegra_xusb_clk_enable()
863 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_enable()
865 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_enable()
867 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_enable()
869 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_enable()
871 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_enable()
873 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_enable()
879 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_disable()
880 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_disable()
881 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_disable()
882 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_disable()
883 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_disable()
884 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_disable()
892 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_enable()
893 err = phy_init(tegra->phys[i]); in tegra_xusb_phy_enable()
897 err = phy_power_on(tegra->phys[i]); in tegra_xusb_phy_enable()
899 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
907 while (i--) { in tegra_xusb_phy_enable()
908 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_enable()
909 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
919 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_disable()
920 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_disable()
921 phy_exit(tegra->phys[i]); in tegra_xusb_phy_disable()
928 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_init_context()
930 tegra->context.ipfs = devm_kcalloc(tegra->dev, soc->ipfs.num_offsets, in tegra_xusb_init_context()
932 if (!tegra->context.ipfs) in tegra_xusb_init_context()
933 return -ENOMEM; in tegra_xusb_init_context()
935 tegra->context.fpci = devm_kcalloc(tegra->dev, soc->fpci.num_offsets, in tegra_xusb_init_context()
937 if (!tegra->context.fpci) in tegra_xusb_init_context()
938 return -ENOMEM; in tegra_xusb_init_context()
955 err = request_firmware(&fw, tegra->soc->firmware, tegra->dev); in tegra_xusb_request_firmware()
957 dev_err(tegra->dev, "failed to request firmware: %d\n", err); in tegra_xusb_request_firmware()
962 header = (struct tegra_xusb_fw_header *)fw->data; in tegra_xusb_request_firmware()
963 tegra->fw.size = le32_to_cpu(header->fwimg_len); in tegra_xusb_request_firmware()
965 tegra->fw.virt = dma_alloc_coherent(tegra->dev, tegra->fw.size, in tegra_xusb_request_firmware()
966 &tegra->fw.phys, GFP_KERNEL); in tegra_xusb_request_firmware()
967 if (!tegra->fw.virt) { in tegra_xusb_request_firmware()
968 dev_err(tegra->dev, "failed to allocate memory for firmware\n"); in tegra_xusb_request_firmware()
970 return -ENOMEM; in tegra_xusb_request_firmware()
973 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_request_firmware()
974 memcpy(tegra->fw.virt, fw->data, tegra->fw.size); in tegra_xusb_request_firmware()
987 cap_regs = tegra->regs; in tegra_xusb_wait_for_falcon()
988 op_regs = tegra->regs + HC_LENGTH(readl(&cap_regs->hc_capbase)); in tegra_xusb_wait_for_falcon()
990 ret = readl_poll_timeout(&op_regs->status, value, !(value & STS_CNR), 1000, 200000); in tegra_xusb_wait_for_falcon()
993 dev_err(tegra->dev, "XHCI Controller not ready. Falcon state: 0x%x\n", in tegra_xusb_wait_for_falcon()
1003 struct device *dev = tegra->dev; in tegra_xusb_load_firmware_rom()
1009 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_load_firmware_rom()
1018 csb_writel(tegra, tegra->fw.size, XUSB_CSB_MP_ILOAD_ATTR); in tegra_xusb_load_firmware_rom()
1024 address = tegra->fw.phys + sizeof(*header); in tegra_xusb_load_firmware_rom()
1038 code_tag_blocks = DIV_ROUND_UP(le32_to_cpu(header->boot_codetag), in tegra_xusb_load_firmware_rom()
1040 code_size_blocks = DIV_ROUND_UP(le32_to_cpu(header->boot_codesize), in tegra_xusb_load_firmware_rom()
1054 /* Setup Falcon auto-fill. */ in tegra_xusb_load_firmware_rom()
1076 csb_writel(tegra, le32_to_cpu(header->boot_codetag), in tegra_xusb_load_firmware_rom()
1083 return -EIO; in tegra_xusb_load_firmware_rom()
1085 timestamp = le32_to_cpu(header->fwimg_created_time); in tegra_xusb_load_firmware_rom()
1111 return -EIO; in tegra_xusb_init_ifr_firmware()
1117 dev_info(tegra->dev, "Firmware timestamp: %ptTs UTC\n", &timestamp); in tegra_xusb_init_ifr_firmware()
1124 if (!tegra->soc->firmware) in tegra_xusb_load_firmware()
1133 if (!tegra->use_genpd) in tegra_xusb_powerdomain_remove()
1136 if (!IS_ERR_OR_NULL(tegra->genpd_dev_ss)) in tegra_xusb_powerdomain_remove()
1137 dev_pm_domain_detach(tegra->genpd_dev_ss, true); in tegra_xusb_powerdomain_remove()
1138 if (!IS_ERR_OR_NULL(tegra->genpd_dev_host)) in tegra_xusb_powerdomain_remove()
1139 dev_pm_domain_detach(tegra->genpd_dev_host, true); in tegra_xusb_powerdomain_remove()
1147 tegra->genpd_dev_host = dev_pm_domain_attach_by_name(dev, "xusb_host"); in tegra_xusb_powerdomain_init()
1148 if (IS_ERR(tegra->genpd_dev_host)) { in tegra_xusb_powerdomain_init()
1149 err = PTR_ERR(tegra->genpd_dev_host); in tegra_xusb_powerdomain_init()
1150 dev_err(dev, "failed to get host pm-domain: %d\n", err); in tegra_xusb_powerdomain_init()
1154 tegra->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "xusb_ss"); in tegra_xusb_powerdomain_init()
1155 if (IS_ERR(tegra->genpd_dev_ss)) { in tegra_xusb_powerdomain_init()
1156 err = PTR_ERR(tegra->genpd_dev_ss); in tegra_xusb_powerdomain_init()
1157 dev_err(dev, "failed to get superspeed pm-domain: %d\n", err); in tegra_xusb_powerdomain_init()
1161 tegra->use_genpd = true; in tegra_xusb_powerdomain_init()
1168 struct device *dev = tegra->dev; in tegra_xusb_unpowergate_partitions()
1171 if (tegra->use_genpd) { in tegra_xusb_unpowergate_partitions()
1172 rc = pm_runtime_resume_and_get(tegra->genpd_dev_ss); in tegra_xusb_unpowergate_partitions()
1178 rc = pm_runtime_resume_and_get(tegra->genpd_dev_host); in tegra_xusb_unpowergate_partitions()
1181 pm_runtime_put_sync(tegra->genpd_dev_ss); in tegra_xusb_unpowergate_partitions()
1186 tegra->ss_clk, in tegra_xusb_unpowergate_partitions()
1187 tegra->ss_rst); in tegra_xusb_unpowergate_partitions()
1194 tegra->host_clk, in tegra_xusb_unpowergate_partitions()
1195 tegra->host_rst); in tegra_xusb_unpowergate_partitions()
1208 struct device *dev = tegra->dev; in tegra_xusb_powergate_partitions()
1211 if (tegra->use_genpd) { in tegra_xusb_powergate_partitions()
1212 rc = pm_runtime_put_sync(tegra->genpd_dev_host); in tegra_xusb_powergate_partitions()
1218 rc = pm_runtime_put_sync(tegra->genpd_dev_ss); in tegra_xusb_powergate_partitions()
1221 pm_runtime_get_sync(tegra->genpd_dev_host); in tegra_xusb_powergate_partitions()
1235 tegra->host_clk, in tegra_xusb_powergate_partitions()
1236 tegra->host_rst); in tegra_xusb_powergate_partitions()
1255 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in __tegra_xusb_enable_firmware_messages()
1264 mutex_lock(&tegra->lock); in tegra_xusb_padctl_irq()
1266 if (tegra->suspended) { in tegra_xusb_padctl_irq()
1267 mutex_unlock(&tegra->lock); in tegra_xusb_padctl_irq()
1271 mutex_unlock(&tegra->lock); in tegra_xusb_padctl_irq()
1273 pm_runtime_resume(tegra->dev); in tegra_xusb_padctl_irq()
1282 mutex_lock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1284 mutex_unlock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1292 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_set_port_power()
1293 struct usb_hcd *hcd = main ? xhci->main_hcd : xhci->shared_hcd; in tegra_xhci_set_port_power()
1296 u16 wIndex = main ? tegra->otg_usb2_port + 1 : tegra->otg_usb3_port + 1; in tegra_xhci_set_port_power()
1301 dev_dbg(tegra->dev, "%s():%s %s port power\n", __func__, in tegra_xhci_set_port_power()
1304 hcd->driver->hub_control(hcd, typeReq, USB_PORT_FEAT_POWER, wIndex, in tegra_xhci_set_port_power()
1317 } while (--wait > 0); in tegra_xhci_set_port_power()
1320 dev_info(tegra->dev, "failed to %s %s PP %d\n", in tegra_xhci_set_port_power()
1330 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_get_phy()
1331 if (!strncmp(tegra->soc->phy_types[i].name, name, in tegra_xusb_get_phy()
1333 return tegra->phys[phy_count+port]; in tegra_xusb_get_phy()
1335 phy_count += tegra->soc->phy_types[i].num; in tegra_xusb_get_phy()
1345 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_id_work()
1348 tegra->otg_usb2_port); in tegra_xhci_id_work()
1352 dev_dbg(tegra->dev, "host mode %s\n", tegra->host_mode ? "on" : "off"); in tegra_xhci_id_work()
1354 mutex_lock(&tegra->lock); in tegra_xhci_id_work()
1356 if (tegra->host_mode) in tegra_xhci_id_work()
1361 mutex_unlock(&tegra->lock); in tegra_xhci_id_work()
1363 tegra->otg_usb3_port = tegra_xusb_padctl_get_usb3_companion(tegra->padctl, in tegra_xhci_id_work()
1364 tegra->otg_usb2_port); in tegra_xhci_id_work()
1366 if (tegra->host_mode) { in tegra_xhci_id_work()
1368 if (tegra->otg_usb3_port >= 0) { in tegra_xhci_id_work()
1369 if (tegra->soc->otg_reset_sspi) { in tegra_xhci_id_work()
1372 xhci->shared_hcd, GetPortStatus, in tegra_xhci_id_work()
1373 0, tegra->otg_usb3_port+1, in tegra_xhci_id_work()
1381 msg.data = tegra->otg_usb3_port+1; in tegra_xhci_id_work()
1385 dev_info(tegra->dev, in tegra_xhci_id_work()
1397 if (tegra->otg_usb3_port >= 0) in tegra_xhci_id_work()
1407 return (tegra->usbphy[index] != NULL); in is_usb2_otg_phy()
1412 struct tegra_xusb_padctl *padctl = tegra->padctl; in is_usb3_otg_phy()
1416 for (i = 0; i < tegra->num_usb_phys; i++) { in is_usb3_otg_phy()
1429 if (strcmp(tegra->soc->phy_types[phy_type].name, "hsic") == 0) in is_host_mode_phy()
1432 if (strcmp(tegra->soc->phy_types[phy_type].name, "usb2") == 0) { in is_host_mode_phy()
1434 return ((index == tegra->otg_usb2_port) && tegra->host_mode); in is_host_mode_phy()
1439 if (strcmp(tegra->soc->phy_types[phy_type].name, "usb3") == 0) { in is_host_mode_phy()
1441 return ((index == tegra->otg_usb3_port) && tegra->host_mode); in is_host_mode_phy()
1455 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_get_usb2_port()
1456 if (tegra->usbphy[i] && usbphy == tegra->usbphy[i]) in tegra_xusb_get_usb2_port()
1460 return -1; in tegra_xusb_get_usb2_port()
1470 dev_dbg(tegra->dev, "%s(): action is %d", __func__, usbphy->last_event); in tegra_xhci_id_notify()
1472 if ((tegra->host_mode && usbphy->last_event == USB_EVENT_ID) || in tegra_xhci_id_notify()
1473 (!tegra->host_mode && usbphy->last_event != USB_EVENT_ID)) { in tegra_xhci_id_notify()
1474 dev_dbg(tegra->dev, "Same role(%d) received. Ignore", in tegra_xhci_id_notify()
1475 tegra->host_mode); in tegra_xhci_id_notify()
1479 tegra->otg_usb2_port = tegra_xusb_get_usb2_port(tegra, usbphy); in tegra_xhci_id_notify()
1481 tegra->host_mode = (usbphy->last_event == USB_EVENT_ID) ? true : false; in tegra_xhci_id_notify()
1483 schedule_work(&tegra->id_work); in tegra_xhci_id_notify()
1492 tegra->usbphy = devm_kcalloc(tegra->dev, tegra->num_usb_phys, in tegra_xusb_init_usb_phy()
1493 sizeof(*tegra->usbphy), GFP_KERNEL); in tegra_xusb_init_usb_phy()
1494 if (!tegra->usbphy) in tegra_xusb_init_usb_phy()
1495 return -ENOMEM; in tegra_xusb_init_usb_phy()
1497 INIT_WORK(&tegra->id_work, tegra_xhci_id_work); in tegra_xusb_init_usb_phy()
1498 tegra->id_nb.notifier_call = tegra_xhci_id_notify; in tegra_xusb_init_usb_phy()
1499 tegra->otg_usb2_port = -EINVAL; in tegra_xusb_init_usb_phy()
1500 tegra->otg_usb3_port = -EINVAL; in tegra_xusb_init_usb_phy()
1502 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_init_usb_phy()
1508 tegra->usbphy[i] = devm_usb_get_phy_by_node(tegra->dev, in tegra_xusb_init_usb_phy()
1509 phy->dev.of_node, in tegra_xusb_init_usb_phy()
1510 &tegra->id_nb); in tegra_xusb_init_usb_phy()
1511 if (!IS_ERR(tegra->usbphy[i])) { in tegra_xusb_init_usb_phy()
1512 dev_dbg(tegra->dev, "usbphy-%d registered", i); in tegra_xusb_init_usb_phy()
1513 otg_set_host(tegra->usbphy[i]->otg, &tegra->hcd->self); in tegra_xusb_init_usb_phy()
1516 * usb-phy is optional, continue if its not available. in tegra_xusb_init_usb_phy()
1518 tegra->usbphy[i] = NULL; in tegra_xusb_init_usb_phy()
1529 cancel_work_sync(&tegra->id_work); in tegra_xusb_deinit_usb_phy()
1531 for (i = 0; i < tegra->num_usb_phys; i++) in tegra_xusb_deinit_usb_phy()
1532 if (tegra->usbphy[i]) in tegra_xusb_deinit_usb_phy()
1533 otg_set_host(tegra->usbphy[i]->otg, NULL); in tegra_xusb_deinit_usb_phy()
1548 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_xusb_probe()
1550 return -ENOMEM; in tegra_xusb_probe()
1552 tegra->soc = of_device_get_match_data(&pdev->dev); in tegra_xusb_probe()
1553 mutex_init(&tegra->lock); in tegra_xusb_probe()
1554 tegra->dev = &pdev->dev; in tegra_xusb_probe()
1560 tegra->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &regs); in tegra_xusb_probe()
1561 if (IS_ERR(tegra->regs)) in tegra_xusb_probe()
1562 return PTR_ERR(tegra->regs); in tegra_xusb_probe()
1564 tegra->fpci_base = devm_platform_ioremap_resource(pdev, 1); in tegra_xusb_probe()
1565 if (IS_ERR(tegra->fpci_base)) in tegra_xusb_probe()
1566 return PTR_ERR(tegra->fpci_base); in tegra_xusb_probe()
1568 if (tegra->soc->has_ipfs) { in tegra_xusb_probe()
1569 tegra->ipfs_base = devm_platform_ioremap_resource(pdev, 2); in tegra_xusb_probe()
1570 if (IS_ERR(tegra->ipfs_base)) in tegra_xusb_probe()
1571 return PTR_ERR(tegra->ipfs_base); in tegra_xusb_probe()
1572 } else if (tegra->soc->has_bar2) { in tegra_xusb_probe()
1573 tegra->bar2_base = devm_platform_get_and_ioremap_resource(pdev, 2, &tegra->bar2); in tegra_xusb_probe()
1574 if (IS_ERR(tegra->bar2_base)) in tegra_xusb_probe()
1575 return PTR_ERR(tegra->bar2_base); in tegra_xusb_probe()
1578 tegra->xhci_irq = platform_get_irq(pdev, 0); in tegra_xusb_probe()
1579 if (tegra->xhci_irq < 0) in tegra_xusb_probe()
1580 return tegra->xhci_irq; in tegra_xusb_probe()
1582 tegra->mbox_irq = platform_get_irq(pdev, 1); in tegra_xusb_probe()
1583 if (tegra->mbox_irq < 0) in tegra_xusb_probe()
1584 return tegra->mbox_irq; in tegra_xusb_probe()
1586 tegra->padctl = tegra_xusb_padctl_get(&pdev->dev); in tegra_xusb_probe()
1587 if (IS_ERR(tegra->padctl)) in tegra_xusb_probe()
1588 return PTR_ERR(tegra->padctl); in tegra_xusb_probe()
1590 np = of_parse_phandle(pdev->dev.of_node, "nvidia,xusb-padctl", 0); in tegra_xusb_probe()
1592 err = -ENODEV; in tegra_xusb_probe()
1596 tegra->padctl_irq = of_irq_get(np, 0); in tegra_xusb_probe()
1597 if (tegra->padctl_irq == -EPROBE_DEFER) { in tegra_xusb_probe()
1598 err = tegra->padctl_irq; in tegra_xusb_probe()
1600 } else if (tegra->padctl_irq <= 0) { in tegra_xusb_probe()
1601 /* Older device-trees don't have padctrl interrupt */ in tegra_xusb_probe()
1602 tegra->padctl_irq = 0; in tegra_xusb_probe()
1603 dev_dbg(&pdev->dev, in tegra_xusb_probe()
1607 tegra->host_clk = devm_clk_get(&pdev->dev, "xusb_host"); in tegra_xusb_probe()
1608 if (IS_ERR(tegra->host_clk)) { in tegra_xusb_probe()
1609 err = PTR_ERR(tegra->host_clk); in tegra_xusb_probe()
1610 dev_err(&pdev->dev, "failed to get xusb_host: %d\n", err); in tegra_xusb_probe()
1614 tegra->falcon_clk = devm_clk_get(&pdev->dev, "xusb_falcon_src"); in tegra_xusb_probe()
1615 if (IS_ERR(tegra->falcon_clk)) { in tegra_xusb_probe()
1616 err = PTR_ERR(tegra->falcon_clk); in tegra_xusb_probe()
1617 dev_err(&pdev->dev, "failed to get xusb_falcon_src: %d\n", err); in tegra_xusb_probe()
1621 tegra->ss_clk = devm_clk_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1622 if (IS_ERR(tegra->ss_clk)) { in tegra_xusb_probe()
1623 err = PTR_ERR(tegra->ss_clk); in tegra_xusb_probe()
1624 dev_err(&pdev->dev, "failed to get xusb_ss: %d\n", err); in tegra_xusb_probe()
1628 tegra->ss_src_clk = devm_clk_get(&pdev->dev, "xusb_ss_src"); in tegra_xusb_probe()
1629 if (IS_ERR(tegra->ss_src_clk)) { in tegra_xusb_probe()
1630 err = PTR_ERR(tegra->ss_src_clk); in tegra_xusb_probe()
1631 dev_err(&pdev->dev, "failed to get xusb_ss_src: %d\n", err); in tegra_xusb_probe()
1635 tegra->hs_src_clk = devm_clk_get(&pdev->dev, "xusb_hs_src"); in tegra_xusb_probe()
1636 if (IS_ERR(tegra->hs_src_clk)) { in tegra_xusb_probe()
1637 err = PTR_ERR(tegra->hs_src_clk); in tegra_xusb_probe()
1638 dev_err(&pdev->dev, "failed to get xusb_hs_src: %d\n", err); in tegra_xusb_probe()
1642 tegra->fs_src_clk = devm_clk_get(&pdev->dev, "xusb_fs_src"); in tegra_xusb_probe()
1643 if (IS_ERR(tegra->fs_src_clk)) { in tegra_xusb_probe()
1644 err = PTR_ERR(tegra->fs_src_clk); in tegra_xusb_probe()
1645 dev_err(&pdev->dev, "failed to get xusb_fs_src: %d\n", err); in tegra_xusb_probe()
1649 tegra->pll_u_480m = devm_clk_get(&pdev->dev, "pll_u_480m"); in tegra_xusb_probe()
1650 if (IS_ERR(tegra->pll_u_480m)) { in tegra_xusb_probe()
1651 err = PTR_ERR(tegra->pll_u_480m); in tegra_xusb_probe()
1652 dev_err(&pdev->dev, "failed to get pll_u_480m: %d\n", err); in tegra_xusb_probe()
1656 tegra->clk_m = devm_clk_get(&pdev->dev, "clk_m"); in tegra_xusb_probe()
1657 if (IS_ERR(tegra->clk_m)) { in tegra_xusb_probe()
1658 err = PTR_ERR(tegra->clk_m); in tegra_xusb_probe()
1659 dev_err(&pdev->dev, "failed to get clk_m: %d\n", err); in tegra_xusb_probe()
1663 tegra->pll_e = devm_clk_get(&pdev->dev, "pll_e"); in tegra_xusb_probe()
1664 if (IS_ERR(tegra->pll_e)) { in tegra_xusb_probe()
1665 err = PTR_ERR(tegra->pll_e); in tegra_xusb_probe()
1666 dev_err(&pdev->dev, "failed to get pll_e: %d\n", err); in tegra_xusb_probe()
1670 if (!of_property_read_bool(pdev->dev.of_node, "power-domains")) { in tegra_xusb_probe()
1671 tegra->host_rst = devm_reset_control_get(&pdev->dev, in tegra_xusb_probe()
1673 if (IS_ERR(tegra->host_rst)) { in tegra_xusb_probe()
1674 err = PTR_ERR(tegra->host_rst); in tegra_xusb_probe()
1675 dev_err(&pdev->dev, in tegra_xusb_probe()
1680 tegra->ss_rst = devm_reset_control_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1681 if (IS_ERR(tegra->ss_rst)) { in tegra_xusb_probe()
1682 err = PTR_ERR(tegra->ss_rst); in tegra_xusb_probe()
1683 dev_err(&pdev->dev, "failed to get xusb_ss reset: %d\n", in tegra_xusb_probe()
1688 err = tegra_xusb_powerdomain_init(&pdev->dev, tegra); in tegra_xusb_probe()
1693 tegra->supplies = devm_kcalloc(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1694 sizeof(*tegra->supplies), GFP_KERNEL); in tegra_xusb_probe()
1695 if (!tegra->supplies) { in tegra_xusb_probe()
1696 err = -ENOMEM; in tegra_xusb_probe()
1700 regulator_bulk_set_supply_names(tegra->supplies, in tegra_xusb_probe()
1701 tegra->soc->supply_names, in tegra_xusb_probe()
1702 tegra->soc->num_supplies); in tegra_xusb_probe()
1704 err = devm_regulator_bulk_get(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1705 tegra->supplies); in tegra_xusb_probe()
1707 dev_err(&pdev->dev, "failed to get regulators: %d\n", err); in tegra_xusb_probe()
1711 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1712 if (!strncmp(tegra->soc->phy_types[i].name, "usb2", 4)) in tegra_xusb_probe()
1713 tegra->num_usb_phys = tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1714 tegra->num_phys += tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1717 tegra->phys = devm_kcalloc(&pdev->dev, tegra->num_phys, in tegra_xusb_probe()
1718 sizeof(*tegra->phys), GFP_KERNEL); in tegra_xusb_probe()
1719 if (!tegra->phys) { in tegra_xusb_probe()
1720 err = -ENOMEM; in tegra_xusb_probe()
1724 for (i = 0, k = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1727 for (j = 0; j < tegra->soc->phy_types[i].num; j++) { in tegra_xusb_probe()
1728 snprintf(prop, sizeof(prop), "%s-%d", in tegra_xusb_probe()
1729 tegra->soc->phy_types[i].name, j); in tegra_xusb_probe()
1731 phy = devm_phy_optional_get(&pdev->dev, prop); in tegra_xusb_probe()
1733 dev_err(&pdev->dev, in tegra_xusb_probe()
1740 tegra->phys[k++] = phy; in tegra_xusb_probe()
1744 tegra->hcd = usb_create_hcd(&tegra_xhci_hc_driver, &pdev->dev, in tegra_xusb_probe()
1745 dev_name(&pdev->dev)); in tegra_xusb_probe()
1746 if (!tegra->hcd) { in tegra_xusb_probe()
1747 err = -ENOMEM; in tegra_xusb_probe()
1751 tegra->hcd->skip_phy_initialization = 1; in tegra_xusb_probe()
1752 tegra->hcd->regs = tegra->regs; in tegra_xusb_probe()
1753 tegra->hcd->rsrc_start = regs->start; in tegra_xusb_probe()
1754 tegra->hcd->rsrc_len = resource_size(regs); in tegra_xusb_probe()
1764 dev_err(tegra->dev, "failed to enable clocks: %d\n", err); in tegra_xusb_probe()
1768 err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_probe()
1770 dev_err(tegra->dev, "failed to enable regulators: %d\n", err); in tegra_xusb_probe()
1776 dev_err(&pdev->dev, "failed to enable PHYs: %d\n", err); in tegra_xusb_probe()
1784 err = dma_set_mask_and_coherent(tegra->dev, DMA_BIT_MASK(40)); in tegra_xusb_probe()
1786 dev_err(&pdev->dev, "failed to set DMA mask: %d\n", err); in tegra_xusb_probe()
1790 if (tegra->soc->firmware) { in tegra_xusb_probe()
1793 dev_err(&pdev->dev, in tegra_xusb_probe()
1807 dev_err(&pdev->dev, "failed to load firmware: %d\n", err); in tegra_xusb_probe()
1811 err = usb_add_hcd(tegra->hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1813 dev_err(&pdev->dev, "failed to add USB HCD: %d\n", err); in tegra_xusb_probe()
1817 device_wakeup_enable(tegra->hcd->self.controller); in tegra_xusb_probe()
1819 xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_probe()
1821 xhci->shared_hcd = usb_create_shared_hcd(&tegra_xhci_hc_driver, in tegra_xusb_probe()
1822 &pdev->dev, in tegra_xusb_probe()
1823 dev_name(&pdev->dev), in tegra_xusb_probe()
1824 tegra->hcd); in tegra_xusb_probe()
1825 if (!xhci->shared_hcd) { in tegra_xusb_probe()
1826 dev_err(&pdev->dev, "failed to create shared HCD\n"); in tegra_xusb_probe()
1827 err = -ENOMEM; in tegra_xusb_probe()
1831 if (HCC_MAX_PSA(xhci->hcc_params) >= 4) in tegra_xusb_probe()
1832 xhci->shared_hcd->can_do_streams = 1; in tegra_xusb_probe()
1834 err = usb_add_hcd(xhci->shared_hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1836 dev_err(&pdev->dev, "failed to add shared HCD: %d\n", err); in tegra_xusb_probe()
1840 err = devm_request_threaded_irq(&pdev->dev, tegra->mbox_irq, in tegra_xusb_probe()
1843 dev_name(&pdev->dev), tegra); in tegra_xusb_probe()
1845 dev_err(&pdev->dev, "failed to request IRQ: %d\n", err); in tegra_xusb_probe()
1849 if (tegra->padctl_irq) { in tegra_xusb_probe()
1850 err = devm_request_threaded_irq(&pdev->dev, tegra->padctl_irq, in tegra_xusb_probe()
1852 IRQF_ONESHOT, dev_name(&pdev->dev), in tegra_xusb_probe()
1855 dev_err(&pdev->dev, "failed to request padctl IRQ: %d\n", err); in tegra_xusb_probe()
1862 dev_err(&pdev->dev, "failed to enable messages: %d\n", err); in tegra_xusb_probe()
1868 dev_err(&pdev->dev, "failed to init USB PHY: %d\n", err); in tegra_xusb_probe()
1873 device_init_wakeup(&tegra->hcd->self.root_hub->dev, true); in tegra_xusb_probe()
1874 device_init_wakeup(&xhci->shared_hcd->self.root_hub->dev, true); in tegra_xusb_probe()
1876 pm_runtime_use_autosuspend(tegra->dev); in tegra_xusb_probe()
1877 pm_runtime_set_autosuspend_delay(tegra->dev, 2000); in tegra_xusb_probe()
1878 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_probe()
1879 pm_runtime_set_active(tegra->dev); in tegra_xusb_probe()
1881 if (tegra->padctl_irq) { in tegra_xusb_probe()
1882 device_init_wakeup(tegra->dev, true); in tegra_xusb_probe()
1883 pm_runtime_enable(tegra->dev); in tegra_xusb_probe()
1889 usb_remove_hcd(xhci->shared_hcd); in tegra_xusb_probe()
1891 usb_put_hcd(xhci->shared_hcd); in tegra_xusb_probe()
1893 usb_remove_hcd(tegra->hcd); in tegra_xusb_probe()
1897 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_probe()
1898 tegra->fw.phys); in tegra_xusb_probe()
1902 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_probe()
1906 usb_put_hcd(tegra->hcd); in tegra_xusb_probe()
1908 tegra_xusb_powerdomain_remove(&pdev->dev, tegra); in tegra_xusb_probe()
1911 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_probe()
1918 tegra_xusb_powerdomain_remove(tegra->dev, tegra); in tegra_xusb_disable()
1921 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_disable()
1927 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_remove()
1931 pm_runtime_get_sync(&pdev->dev); in tegra_xusb_remove()
1932 usb_remove_hcd(xhci->shared_hcd); in tegra_xusb_remove()
1933 usb_put_hcd(xhci->shared_hcd); in tegra_xusb_remove()
1934 xhci->shared_hcd = NULL; in tegra_xusb_remove()
1935 usb_remove_hcd(tegra->hcd); in tegra_xusb_remove()
1936 usb_put_hcd(tegra->hcd); in tegra_xusb_remove()
1938 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_remove()
1939 tegra->fw.phys); in tegra_xusb_remove()
1941 if (tegra->padctl_irq) in tegra_xusb_remove()
1942 pm_runtime_disable(&pdev->dev); in tegra_xusb_remove()
1944 pm_runtime_put(&pdev->dev); in tegra_xusb_remove()
1947 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_remove()
1954 pm_runtime_get_sync(&pdev->dev); in tegra_xusb_shutdown()
1955 disable_irq(tegra->xhci_irq); in tegra_xusb_shutdown()
1956 xhci_shutdown(tegra->hcd); in tegra_xusb_shutdown()
1962 struct device *dev = hub->hcd->self.controller; in xhci_hub_ports_suspended()
1967 for (i = 0; i < hub->num_ports; i++) { in xhci_hub_ports_suspended()
1968 value = readl(hub->ports[i]->addr); in xhci_hub_ports_suspended()
1973 dev_info(dev, "%u-%u isn't suspended: %#010x\n", in xhci_hub_ports_suspended()
1974 hub->hcd->self.busnum, i + 1, value); in xhci_hub_ports_suspended()
1984 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_check_ports()
1985 struct xhci_bus_state *bus_state = &xhci->usb2_rhub.bus_state; in tegra_xusb_check_ports()
1989 if (bus_state->bus_suspended) { in tegra_xusb_check_ports()
1996 spin_lock_irqsave(&xhci->lock, flags); in tegra_xusb_check_ports()
1998 if (!xhci_hub_ports_suspended(&xhci->usb2_rhub) || in tegra_xusb_check_ports()
1999 !xhci_hub_ports_suspended(&xhci->usb3_rhub)) in tegra_xusb_check_ports()
2000 err = -EBUSY; in tegra_xusb_check_ports()
2002 spin_unlock_irqrestore(&xhci->lock, flags); in tegra_xusb_check_ports()
2009 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_save_context()
2010 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_save_context()
2013 if (soc->ipfs.num_offsets > 0) { in tegra_xusb_save_context()
2014 for (i = 0; i < soc->ipfs.num_offsets; i++) in tegra_xusb_save_context()
2015 ctx->ipfs[i] = ipfs_readl(tegra, soc->ipfs.offsets[i]); in tegra_xusb_save_context()
2018 if (soc->fpci.num_offsets > 0) { in tegra_xusb_save_context()
2019 for (i = 0; i < soc->fpci.num_offsets; i++) in tegra_xusb_save_context()
2020 ctx->fpci[i] = fpci_readl(tegra, soc->fpci.offsets[i]); in tegra_xusb_save_context()
2026 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_restore_context()
2027 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_restore_context()
2030 if (soc->fpci.num_offsets > 0) { in tegra_xusb_restore_context()
2031 for (i = 0; i < soc->fpci.num_offsets; i++) in tegra_xusb_restore_context()
2032 fpci_writel(tegra, ctx->fpci[i], soc->fpci.offsets[i]); in tegra_xusb_restore_context()
2035 if (soc->ipfs.num_offsets > 0) { in tegra_xusb_restore_context()
2036 for (i = 0; i < soc->ipfs.num_offsets; i++) in tegra_xusb_restore_context()
2037 ipfs_writel(tegra, ctx->ipfs[i], soc->ipfs.offsets[i]); in tegra_xusb_restore_context()
2060 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_enable_phy_sleepwalk_wake()
2061 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_enable_phy_sleepwalk_wake()
2069 for (i = 0, k = 0; i < tegra->soc->num_types; i++) { in tegra_xhci_enable_phy_sleepwalk_wake()
2070 if (strcmp(tegra->soc->phy_types[i].name, "usb3") == 0) in tegra_xhci_enable_phy_sleepwalk_wake()
2071 rhub = &xhci->usb3_rhub; in tegra_xhci_enable_phy_sleepwalk_wake()
2073 rhub = &xhci->usb2_rhub; in tegra_xhci_enable_phy_sleepwalk_wake()
2075 if (strcmp(tegra->soc->phy_types[i].name, "hsic") == 0) in tegra_xhci_enable_phy_sleepwalk_wake()
2076 offset = tegra->soc->ports.usb2.count; in tegra_xhci_enable_phy_sleepwalk_wake()
2080 for (j = 0; j < tegra->soc->phy_types[i].num; j++) { in tegra_xhci_enable_phy_sleepwalk_wake()
2081 phy = tegra->phys[k++]; in tegra_xhci_enable_phy_sleepwalk_wake()
2088 if (index >= rhub->num_ports) in tegra_xhci_enable_phy_sleepwalk_wake()
2094 portsc = readl(rhub->ports[index]->addr); in tegra_xhci_enable_phy_sleepwalk_wake()
2104 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_disable_phy_wake()
2107 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xhci_disable_phy_wake()
2117 for (i = 0; i < tegra->num_phys; i++) { in tegra_xhci_disable_phy_wake()
2118 if (!tegra->phys[i]) in tegra_xhci_disable_phy_wake()
2121 if (tegra_xusb_padctl_remote_wake_detected(padctl, tegra->phys[i])) in tegra_xhci_disable_phy_wake()
2122 dev_dbg(tegra->dev, "%pOF remote wake detected\n", in tegra_xhci_disable_phy_wake()
2123 tegra->phys[i]->dev.of_node); in tegra_xhci_disable_phy_wake()
2125 tegra_xusb_padctl_disable_phy_wake(padctl, tegra->phys[i]); in tegra_xhci_disable_phy_wake()
2131 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_disable_phy_sleepwalk()
2134 for (i = 0; i < tegra->num_phys; i++) { in tegra_xhci_disable_phy_sleepwalk()
2135 if (!tegra->phys[i]) in tegra_xhci_disable_phy_sleepwalk()
2138 tegra_xusb_padctl_disable_phy_sleepwalk(padctl, tegra->phys[i]); in tegra_xhci_disable_phy_sleepwalk()
2147 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xhci_program_utmi_power_lp0_exit()
2148 if (strcmp(tegra->soc->phy_types[i].name, "usb2") == 0) in tegra_xhci_program_utmi_power_lp0_exit()
2152 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xhci_program_utmi_power_lp0_exit()
2157 if (tegra->lp0_utmi_pad_mask & BIT(i)) in tegra_xhci_program_utmi_power_lp0_exit()
2166 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_enter_elpg()
2167 struct device *dev = tegra->dev; in tegra_xusb_enter_elpg()
2176 usbcmd = readl(&xhci->op_regs->command); in tegra_xusb_enter_elpg()
2178 writel(usbcmd, &xhci->op_regs->command); in tegra_xusb_enter_elpg()
2182 dev_err(tegra->dev, "not all ports suspended: %d\n", err); in tegra_xusb_enter_elpg()
2186 for (i = 0; i < xhci->usb2_rhub.num_ports; i++) { in tegra_xusb_enter_elpg()
2187 if (!xhci->usb2_rhub.ports[i]) in tegra_xusb_enter_elpg()
2189 portsc = readl(xhci->usb2_rhub.ports[i]->addr); in tegra_xusb_enter_elpg()
2190 tegra->lp0_utmi_pad_mask &= ~BIT(i); in tegra_xusb_enter_elpg()
2192 tegra->lp0_utmi_pad_mask |= BIT(i); in tegra_xusb_enter_elpg()
2197 dev_err(tegra->dev, "failed to suspend XHCI: %d\n", err); in tegra_xusb_enter_elpg()
2208 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_enter_elpg()
2209 if (!tegra->phys[i]) in tegra_xusb_enter_elpg()
2212 phy_power_off(tegra->phys[i]); in tegra_xusb_enter_elpg()
2214 phy_exit(tegra->phys[i]); in tegra_xusb_enter_elpg()
2221 dev_dbg(tegra->dev, "entering ELPG done\n"); in tegra_xusb_enter_elpg()
2223 usbcmd = readl(&xhci->op_regs->command); in tegra_xusb_enter_elpg()
2225 writel(usbcmd, &xhci->op_regs->command); in tegra_xusb_enter_elpg()
2227 dev_dbg(tegra->dev, "entering ELPG failed\n"); in tegra_xusb_enter_elpg()
2228 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_enter_elpg()
2236 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_exit_elpg()
2237 struct device *dev = tegra->dev; in tegra_xusb_exit_elpg()
2244 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_exit_elpg()
2248 dev_err(tegra->dev, "failed to enable clocks: %d\n", err); in tegra_xusb_exit_elpg()
2259 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_exit_elpg()
2260 if (!tegra->phys[i]) in tegra_xusb_exit_elpg()
2264 phy_init(tegra->phys[i]); in tegra_xusb_exit_elpg()
2266 phy_power_on(tegra->phys[i]); in tegra_xusb_exit_elpg()
2268 if (tegra->suspended) in tegra_xusb_exit_elpg()
2276 dev_err(tegra->dev, "failed to load firmware: %d\n", err); in tegra_xusb_exit_elpg()
2282 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in tegra_xusb_exit_elpg()
2291 dev_err(tegra->dev, "failed to resume XHCI: %d\n", err); in tegra_xusb_exit_elpg()
2295 usbcmd = readl(&xhci->op_regs->command); in tegra_xusb_exit_elpg()
2297 writel(usbcmd, &xhci->op_regs->command); in tegra_xusb_exit_elpg()
2302 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_exit_elpg()
2303 if (!tegra->phys[i]) in tegra_xusb_exit_elpg()
2306 phy_power_off(tegra->phys[i]); in tegra_xusb_exit_elpg()
2308 phy_exit(tegra->phys[i]); in tegra_xusb_exit_elpg()
2327 synchronize_irq(tegra->mbox_irq); in tegra_xusb_suspend()
2329 mutex_lock(&tegra->lock); in tegra_xusb_suspend()
2350 tegra->suspended = true; in tegra_xusb_suspend()
2354 if (enable_irq_wake(tegra->padctl_irq)) in tegra_xusb_suspend()
2359 mutex_unlock(&tegra->lock); in tegra_xusb_suspend()
2369 mutex_lock(&tegra->lock); in tegra_xusb_resume()
2371 if (!tegra->suspended) { in tegra_xusb_resume()
2372 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2378 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2383 if (disable_irq_wake(tegra->padctl_irq)) in tegra_xusb_resume()
2386 tegra->suspended = false; in tegra_xusb_resume()
2387 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2400 synchronize_irq(tegra->mbox_irq); in tegra_xusb_runtime_suspend()
2401 mutex_lock(&tegra->lock); in tegra_xusb_runtime_suspend()
2403 mutex_unlock(&tegra->lock); in tegra_xusb_runtime_suspend()
2413 mutex_lock(&tegra->lock); in tegra_xusb_runtime_resume()
2415 mutex_unlock(&tegra->lock); in tegra_xusb_runtime_resume()
2427 "avddio-pex",
2428 "dvddio-pex",
2429 "avdd-usb",
2430 "hvdd-usb-ss",
2509 "dvddio-pex",
2510 "hvddio-pex",
2511 "avdd-usb",
2521 .firmware = "nvidia/tegra210/xusb.bin",
2544 MODULE_FIRMWARE("nvidia/tegra210/xusb.bin");
2656 { .compatible = "nvidia,tegra124-xusb", .data = &tegra124_soc },
2657 { .compatible = "nvidia,tegra210-xusb", .data = &tegra210_soc },
2658 { .compatible = "nvidia,tegra186-xusb", .data = &tegra186_soc },
2659 { .compatible = "nvidia,tegra194-xusb", .data = &tegra194_soc },
2660 { .compatible = "nvidia,tegra234-xusb", .data = &tegra234_soc },
2670 .name = "tegra-xusb",
2680 if (tegra && tegra->soc->lpm_support) in tegra_xhci_quirks()
2681 xhci->quirks |= XHCI_LPM_SUPPORT; in tegra_xhci_quirks()
2692 struct tegra_xusb *tegra = dev_get_drvdata(hcd->self.controller); in tegra_xhci_hub_control()
2696 int port = (index & 0xff) - 1; in tegra_xhci_hub_control()
2703 rhub = &xhci->usb2_rhub; in tegra_xhci_hub_control()
2704 bus_state = &rhub->bus_state; in tegra_xhci_hub_control()
2705 if (bus_state->resuming_ports && hcd->speed == HCD_USB2) { in tegra_xhci_hub_control()
2706 ports = rhub->ports; in tegra_xhci_hub_control()
2707 i = rhub->num_ports; in tegra_xhci_hub_control()
2708 while (i--) { in tegra_xhci_hub_control()
2709 if (!test_bit(i, &bus_state->resuming_ports)) in tegra_xhci_hub_control()
2711 portsc = readl(ports[i]->addr); in tegra_xhci_hub_control()
2718 if (hcd->speed == HCD_USB2) { in tegra_xhci_hub_control()
2721 if (!index || index > rhub->num_ports) in tegra_xhci_hub_control()
2722 return -EPIPE; in tegra_xhci_hub_control()
2726 if (!index || index > rhub->num_ports) in tegra_xhci_hub_control()
2727 return -EPIPE; in tegra_xhci_hub_control()
2728 ports = rhub->ports; in tegra_xhci_hub_control()
2729 portsc = readl(ports[port]->addr); in tegra_xhci_hub_control()
2739 if (hcd->speed == HCD_USB2) { in tegra_xhci_hub_control()
2743 if (!((hcd->self.otg_port == (port + 1)) && hcd->self.b_hnp_enable)) in tegra_xhci_hub_control()
2747 ports = rhub->ports; in tegra_xhci_hub_control()
2748 portsc = readl(ports[port]->addr); in tegra_xhci_hub_control()
2753 if (!((hcd->self.otg_port == (port + 1)) && hcd->self.b_hnp_enable)) in tegra_xhci_hub_control()
2784 MODULE_DESCRIPTION("NVIDIA Tegra XUSB xHCI host-controller driver");