Lines Matching +full:num +full:- +full:ports

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (c) 2014-2020, NVIDIA CORPORATION. All rights reserved.
11 #include <linux/dma-mapping.h>
196 unsigned int num; member
241 } ports; member
327 return readl(tegra->fpci_base + offset); in fpci_readl()
333 writel(value, tegra->fpci_base + offset); in fpci_writel()
338 return readl(tegra->ipfs_base + offset); in ipfs_readl()
344 writel(value, tegra->ipfs_base + offset); in ipfs_writel()
349 return readl(tegra->bar2_base + offset); in bar2_readl()
355 writel(value, tegra->bar2_base + offset); in bar2_writel()
360 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in csb_readl()
362 return ops->csb_reg_readl(tegra, offset); in csb_readl()
368 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in csb_writel()
370 ops->csb_reg_writel(tegra, value, offset); in csb_writel()
417 struct clk *clk = tegra->ss_src_clk; in tegra_xusb_set_ss_clk()
431 new_parent_rate = clk_get_rate(tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
438 err = clk_set_parent(clk, tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
454 err = clk_set_parent(clk, tegra->clk_m); in tegra_xusb_set_ss_clk()
465 dev_err(tegra->dev, "Invalid SS rate: %lu Hz\n", rate); in tegra_xusb_set_ss_clk()
466 return -EINVAL; in tegra_xusb_set_ss_clk()
470 dev_err(tegra->dev, "SS clock doesn't match requested rate\n"); in tegra_xusb_set_ss_clk()
471 return -EINVAL; in tegra_xusb_set_ss_clk()
480 return (value >> start) & ((1 << count) - 1); in extract_field()
518 return (msg->cmd & CMD_TYPE_MASK) << CMD_TYPE_SHIFT | in tegra_xusb_mbox_pack()
519 (msg->data & CMD_DATA_MASK) << CMD_DATA_SHIFT; in tegra_xusb_mbox_pack()
524 msg->cmd = (value >> CMD_TYPE_SHIFT) & CMD_TYPE_MASK; in tegra_xusb_mbox_unpack()
525 msg->data = (value >> CMD_DATA_SHIFT) & CMD_DATA_MASK; in tegra_xusb_mbox_unpack()
544 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_send()
552 if (!(msg->cmd == MBOX_CMD_ACK || msg->cmd == MBOX_CMD_NAK)) { in tegra_xusb_mbox_send()
553 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
555 dev_err(tegra->dev, "mailbox is busy\n"); in tegra_xusb_mbox_send()
556 return -EBUSY; in tegra_xusb_mbox_send()
559 ops->mbox_reg_writel(tegra, MBOX_OWNER_SW, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
561 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
563 dev_err(tegra->dev, "failed to acquire mailbox\n"); in tegra_xusb_mbox_send()
564 return -EBUSY; in tegra_xusb_mbox_send()
571 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.data_in); in tegra_xusb_mbox_send()
573 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
575 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
581 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
589 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
592 return -ETIMEDOUT; in tegra_xusb_mbox_send()
601 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_irq()
605 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.smi_intr); in tegra_xusb_mbox_irq()
606 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.smi_intr); in tegra_xusb_mbox_irq()
609 dev_err(tegra->dev, "controller firmware hang\n"); in tegra_xusb_mbox_irq()
617 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xusb_mbox_handle()
618 const struct tegra_xusb_soc *soc = tegra->soc; in tegra_xusb_mbox_handle()
619 struct device *dev = tegra->dev; in tegra_xusb_mbox_handle()
628 switch (msg->cmd) { in tegra_xusb_mbox_handle()
631 rsp.data = clk_get_rate(tegra->falcon_clk) / 1000; in tegra_xusb_mbox_handle()
632 if (rsp.data != msg->data) in tegra_xusb_mbox_handle()
641 if (tegra->soc->scale_ss_clock) { in tegra_xusb_mbox_handle()
642 err = tegra_xusb_set_ss_clk(tegra, msg->data * 1000); in tegra_xusb_mbox_handle()
648 rsp.data = clk_get_rate(tegra->ss_src_clk) / 1000; in tegra_xusb_mbox_handle()
651 rsp.data = msg->data; in tegra_xusb_mbox_handle()
665 err = tegra_xusb_padctl_usb3_save_context(padctl, msg->data); in tegra_xusb_mbox_handle()
668 msg->data, err); in tegra_xusb_mbox_handle()
674 rsp.data = msg->data; in tegra_xusb_mbox_handle()
679 if (msg->cmd == MBOX_CMD_STOP_HSIC_IDLE) in tegra_xusb_mbox_handle()
684 mask = extract_field(msg->data, 1 + soc->ports.hsic.offset, in tegra_xusb_mbox_handle()
685 soc->ports.hsic.count); in tegra_xusb_mbox_handle()
702 rsp.data = msg->data; in tegra_xusb_mbox_handle()
707 if (msg->cmd == MBOX_CMD_DISABLE_SS_LFPS_DETECTION) in tegra_xusb_mbox_handle()
712 mask = extract_field(msg->data, 1 + soc->ports.usb3.offset, in tegra_xusb_mbox_handle()
713 soc->ports.usb3.count); in tegra_xusb_mbox_handle()
715 for_each_set_bit(port, &mask, soc->ports.usb3.count) { in tegra_xusb_mbox_handle()
739 rsp.data = msg->data; in tegra_xusb_mbox_handle()
743 dev_warn(dev, "unknown message: %#x\n", msg->cmd); in tegra_xusb_mbox_handle()
759 const struct tegra_xusb_soc_ops *ops = tegra->soc->ops; in tegra_xusb_mbox_thread()
763 mutex_lock(&tegra->lock); in tegra_xusb_mbox_thread()
765 if (pm_runtime_suspended(tegra->dev) || tegra->suspended) in tegra_xusb_mbox_thread()
768 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.data_out); in tegra_xusb_mbox_thread()
771 value = ops->mbox_reg_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
773 ops->mbox_reg_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
777 ops->mbox_reg_writel(tegra, MBOX_OWNER_NONE, tegra->soc->mbox.owner); in tegra_xusb_mbox_thread()
782 mutex_unlock(&tegra->lock); in tegra_xusb_mbox_thread()
788 u32 regs = tegra->hcd->rsrc_start; in tegra_xusb_config()
791 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
806 if (tegra->bar2) { in tegra_xusb_config()
809 value |= tegra->bar2->start & in tegra_xusb_config()
821 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
836 err = clk_prepare_enable(tegra->pll_e); in tegra_xusb_clk_enable()
840 err = clk_prepare_enable(tegra->host_clk); in tegra_xusb_clk_enable()
844 err = clk_prepare_enable(tegra->ss_clk); in tegra_xusb_clk_enable()
848 err = clk_prepare_enable(tegra->falcon_clk); in tegra_xusb_clk_enable()
852 err = clk_prepare_enable(tegra->fs_src_clk); in tegra_xusb_clk_enable()
856 err = clk_prepare_enable(tegra->hs_src_clk); in tegra_xusb_clk_enable()
860 if (tegra->soc->scale_ss_clock) { in tegra_xusb_clk_enable()
869 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_enable()
871 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_enable()
873 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_enable()
875 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_enable()
877 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_enable()
879 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_enable()
885 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_disable()
886 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_disable()
887 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_disable()
888 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_disable()
889 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_disable()
890 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_disable()
898 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_enable()
899 err = phy_init(tegra->phys[i]); in tegra_xusb_phy_enable()
903 err = phy_power_on(tegra->phys[i]); in tegra_xusb_phy_enable()
905 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
913 while (i--) { in tegra_xusb_phy_enable()
914 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_enable()
915 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
925 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_disable()
926 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_disable()
927 phy_exit(tegra->phys[i]); in tegra_xusb_phy_disable()
934 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_init_context()
936 tegra->context.ipfs = devm_kcalloc(tegra->dev, soc->ipfs.num_offsets, in tegra_xusb_init_context()
938 if (!tegra->context.ipfs) in tegra_xusb_init_context()
939 return -ENOMEM; in tegra_xusb_init_context()
941 tegra->context.fpci = devm_kcalloc(tegra->dev, soc->fpci.num_offsets, in tegra_xusb_init_context()
943 if (!tegra->context.fpci) in tegra_xusb_init_context()
944 return -ENOMEM; in tegra_xusb_init_context()
961 err = request_firmware(&fw, tegra->soc->firmware, tegra->dev); in tegra_xusb_request_firmware()
963 dev_err(tegra->dev, "failed to request firmware: %d\n", err); in tegra_xusb_request_firmware()
968 header = (struct tegra_xusb_fw_header *)fw->data; in tegra_xusb_request_firmware()
969 tegra->fw.size = le32_to_cpu(header->fwimg_len); in tegra_xusb_request_firmware()
971 tegra->fw.virt = dma_alloc_coherent(tegra->dev, tegra->fw.size, in tegra_xusb_request_firmware()
972 &tegra->fw.phys, GFP_KERNEL); in tegra_xusb_request_firmware()
973 if (!tegra->fw.virt) { in tegra_xusb_request_firmware()
974 dev_err(tegra->dev, "failed to allocate memory for firmware\n"); in tegra_xusb_request_firmware()
976 return -ENOMEM; in tegra_xusb_request_firmware()
979 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_request_firmware()
980 memcpy(tegra->fw.virt, fw->data, tegra->fw.size); in tegra_xusb_request_firmware()
993 cap_regs = tegra->regs; in tegra_xusb_wait_for_falcon()
994 op_regs = tegra->regs + HC_LENGTH(readl(&cap_regs->hc_capbase)); in tegra_xusb_wait_for_falcon()
996 ret = readl_poll_timeout(&op_regs->status, value, !(value & STS_CNR), 1000, 200000); in tegra_xusb_wait_for_falcon()
999 dev_err(tegra->dev, "XHCI Controller not ready. Falcon state: 0x%x\n", in tegra_xusb_wait_for_falcon()
1009 struct device *dev = tegra->dev; in tegra_xusb_load_firmware_rom()
1015 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_load_firmware_rom()
1024 csb_writel(tegra, tegra->fw.size, XUSB_CSB_MP_ILOAD_ATTR); in tegra_xusb_load_firmware_rom()
1030 address = tegra->fw.phys + sizeof(*header); in tegra_xusb_load_firmware_rom()
1044 code_tag_blocks = DIV_ROUND_UP(le32_to_cpu(header->boot_codetag), in tegra_xusb_load_firmware_rom()
1046 code_size_blocks = DIV_ROUND_UP(le32_to_cpu(header->boot_codesize), in tegra_xusb_load_firmware_rom()
1060 /* Setup Falcon auto-fill. */ in tegra_xusb_load_firmware_rom()
1082 csb_writel(tegra, le32_to_cpu(header->boot_codetag), in tegra_xusb_load_firmware_rom()
1089 return -EIO; in tegra_xusb_load_firmware_rom()
1091 timestamp = le32_to_cpu(header->fwimg_created_time); in tegra_xusb_load_firmware_rom()
1117 return -EIO; in tegra_xusb_init_ifr_firmware()
1123 dev_info(tegra->dev, "Firmware timestamp: %ptTs UTC\n", &timestamp); in tegra_xusb_init_ifr_firmware()
1130 if (!tegra->soc->firmware) in tegra_xusb_load_firmware()
1139 if (!tegra->use_genpd) in tegra_xusb_powerdomain_remove()
1142 if (!IS_ERR_OR_NULL(tegra->genpd_dev_ss)) in tegra_xusb_powerdomain_remove()
1143 dev_pm_domain_detach(tegra->genpd_dev_ss, true); in tegra_xusb_powerdomain_remove()
1144 if (!IS_ERR_OR_NULL(tegra->genpd_dev_host)) in tegra_xusb_powerdomain_remove()
1145 dev_pm_domain_detach(tegra->genpd_dev_host, true); in tegra_xusb_powerdomain_remove()
1153 tegra->genpd_dev_host = dev_pm_domain_attach_by_name(dev, "xusb_host"); in tegra_xusb_powerdomain_init()
1154 if (IS_ERR(tegra->genpd_dev_host)) { in tegra_xusb_powerdomain_init()
1155 err = PTR_ERR(tegra->genpd_dev_host); in tegra_xusb_powerdomain_init()
1156 dev_err(dev, "failed to get host pm-domain: %d\n", err); in tegra_xusb_powerdomain_init()
1160 tegra->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "xusb_ss"); in tegra_xusb_powerdomain_init()
1161 if (IS_ERR(tegra->genpd_dev_ss)) { in tegra_xusb_powerdomain_init()
1162 err = PTR_ERR(tegra->genpd_dev_ss); in tegra_xusb_powerdomain_init()
1163 dev_err(dev, "failed to get superspeed pm-domain: %d\n", err); in tegra_xusb_powerdomain_init()
1167 tegra->use_genpd = true; in tegra_xusb_powerdomain_init()
1174 struct device *dev = tegra->dev; in tegra_xusb_unpowergate_partitions()
1177 if (tegra->use_genpd) { in tegra_xusb_unpowergate_partitions()
1178 rc = pm_runtime_resume_and_get(tegra->genpd_dev_ss); in tegra_xusb_unpowergate_partitions()
1184 rc = pm_runtime_resume_and_get(tegra->genpd_dev_host); in tegra_xusb_unpowergate_partitions()
1187 pm_runtime_put_sync(tegra->genpd_dev_ss); in tegra_xusb_unpowergate_partitions()
1192 tegra->ss_clk, in tegra_xusb_unpowergate_partitions()
1193 tegra->ss_rst); in tegra_xusb_unpowergate_partitions()
1200 tegra->host_clk, in tegra_xusb_unpowergate_partitions()
1201 tegra->host_rst); in tegra_xusb_unpowergate_partitions()
1214 struct device *dev = tegra->dev; in tegra_xusb_powergate_partitions()
1217 if (tegra->use_genpd) { in tegra_xusb_powergate_partitions()
1218 rc = pm_runtime_put_sync(tegra->genpd_dev_host); in tegra_xusb_powergate_partitions()
1224 rc = pm_runtime_put_sync(tegra->genpd_dev_ss); in tegra_xusb_powergate_partitions()
1227 pm_runtime_get_sync(tegra->genpd_dev_host); in tegra_xusb_powergate_partitions()
1241 tegra->host_clk, in tegra_xusb_powergate_partitions()
1242 tegra->host_rst); in tegra_xusb_powergate_partitions()
1261 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in __tegra_xusb_enable_firmware_messages()
1270 mutex_lock(&tegra->lock); in tegra_xusb_padctl_irq()
1272 if (tegra->suspended) { in tegra_xusb_padctl_irq()
1273 mutex_unlock(&tegra->lock); in tegra_xusb_padctl_irq()
1277 mutex_unlock(&tegra->lock); in tegra_xusb_padctl_irq()
1279 pm_runtime_resume(tegra->dev); in tegra_xusb_padctl_irq()
1288 mutex_lock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1290 mutex_unlock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1298 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_set_port_power()
1299 struct usb_hcd *hcd = main ? xhci->main_hcd : xhci->shared_hcd; in tegra_xhci_set_port_power()
1302 u16 wIndex = main ? tegra->otg_usb2_port + 1 : tegra->otg_usb3_port + 1; in tegra_xhci_set_port_power()
1307 dev_dbg(tegra->dev, "%s():%s %s port power\n", __func__, in tegra_xhci_set_port_power()
1310 hcd->driver->hub_control(hcd, typeReq, USB_PORT_FEAT_POWER, wIndex, in tegra_xhci_set_port_power()
1323 } while (--wait > 0); in tegra_xhci_set_port_power()
1326 dev_info(tegra->dev, "failed to %s %s PP %d\n", in tegra_xhci_set_port_power()
1336 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_get_phy()
1337 if (!strncmp(tegra->soc->phy_types[i].name, name, in tegra_xusb_get_phy()
1339 return tegra->phys[phy_count+port]; in tegra_xusb_get_phy()
1341 phy_count += tegra->soc->phy_types[i].num; in tegra_xusb_get_phy()
1351 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_id_work()
1354 tegra->otg_usb2_port); in tegra_xhci_id_work()
1358 dev_dbg(tegra->dev, "host mode %s\n", str_on_off(tegra->host_mode)); in tegra_xhci_id_work()
1360 mutex_lock(&tegra->lock); in tegra_xhci_id_work()
1362 if (tegra->host_mode) in tegra_xhci_id_work()
1367 mutex_unlock(&tegra->lock); in tegra_xhci_id_work()
1369 tegra->otg_usb3_port = tegra_xusb_padctl_get_usb3_companion(tegra->padctl, in tegra_xhci_id_work()
1370 tegra->otg_usb2_port); in tegra_xhci_id_work()
1372 pm_runtime_get_sync(tegra->dev); in tegra_xhci_id_work()
1373 if (tegra->host_mode) { in tegra_xhci_id_work()
1375 if (tegra->otg_usb3_port >= 0) { in tegra_xhci_id_work()
1376 if (tegra->soc->otg_reset_sspi) { in tegra_xhci_id_work()
1379 xhci->shared_hcd, GetPortStatus, in tegra_xhci_id_work()
1380 0, tegra->otg_usb3_port+1, in tegra_xhci_id_work()
1388 msg.data = tegra->otg_usb3_port+1; in tegra_xhci_id_work()
1392 dev_info(tegra->dev, in tegra_xhci_id_work()
1404 if (tegra->otg_usb3_port >= 0) in tegra_xhci_id_work()
1409 pm_runtime_put_autosuspend(tegra->dev); in tegra_xhci_id_work()
1415 return (tegra->usbphy[index] != NULL); in is_usb2_otg_phy()
1420 struct tegra_xusb_padctl *padctl = tegra->padctl; in is_usb3_otg_phy()
1424 for (i = 0; i < tegra->num_usb_phys; i++) { in is_usb3_otg_phy()
1437 if (strcmp(tegra->soc->phy_types[phy_type].name, "hsic") == 0) in is_host_mode_phy()
1440 if (strcmp(tegra->soc->phy_types[phy_type].name, "usb2") == 0) { in is_host_mode_phy()
1442 return ((index == tegra->otg_usb2_port) && tegra->host_mode); in is_host_mode_phy()
1447 if (strcmp(tegra->soc->phy_types[phy_type].name, "usb3") == 0) { in is_host_mode_phy()
1449 return ((index == tegra->otg_usb3_port) && tegra->host_mode); in is_host_mode_phy()
1463 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_get_usb2_port()
1464 if (tegra->usbphy[i] && usbphy == tegra->usbphy[i]) in tegra_xusb_get_usb2_port()
1468 return -1; in tegra_xusb_get_usb2_port()
1478 dev_dbg(tegra->dev, "%s(): action is %d", __func__, usbphy->last_event); in tegra_xhci_id_notify()
1480 if ((tegra->host_mode && usbphy->last_event == USB_EVENT_ID) || in tegra_xhci_id_notify()
1481 (!tegra->host_mode && usbphy->last_event != USB_EVENT_ID)) { in tegra_xhci_id_notify()
1482 dev_dbg(tegra->dev, "Same role(%d) received. Ignore", in tegra_xhci_id_notify()
1483 tegra->host_mode); in tegra_xhci_id_notify()
1487 tegra->otg_usb2_port = tegra_xusb_get_usb2_port(tegra, usbphy); in tegra_xhci_id_notify()
1489 tegra->host_mode = usbphy->last_event == USB_EVENT_ID; in tegra_xhci_id_notify()
1491 schedule_work(&tegra->id_work); in tegra_xhci_id_notify()
1500 tegra->usbphy = devm_kcalloc(tegra->dev, tegra->num_usb_phys, in tegra_xusb_init_usb_phy()
1501 sizeof(*tegra->usbphy), GFP_KERNEL); in tegra_xusb_init_usb_phy()
1502 if (!tegra->usbphy) in tegra_xusb_init_usb_phy()
1503 return -ENOMEM; in tegra_xusb_init_usb_phy()
1505 INIT_WORK(&tegra->id_work, tegra_xhci_id_work); in tegra_xusb_init_usb_phy()
1506 tegra->id_nb.notifier_call = tegra_xhci_id_notify; in tegra_xusb_init_usb_phy()
1507 tegra->otg_usb2_port = -EINVAL; in tegra_xusb_init_usb_phy()
1508 tegra->otg_usb3_port = -EINVAL; in tegra_xusb_init_usb_phy()
1510 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_init_usb_phy()
1516 tegra->usbphy[i] = devm_usb_get_phy_by_node(tegra->dev, in tegra_xusb_init_usb_phy()
1517 phy->dev.of_node, in tegra_xusb_init_usb_phy()
1518 &tegra->id_nb); in tegra_xusb_init_usb_phy()
1519 if (!IS_ERR(tegra->usbphy[i])) { in tegra_xusb_init_usb_phy()
1520 dev_dbg(tegra->dev, "usbphy-%d registered", i); in tegra_xusb_init_usb_phy()
1521 otg_set_host(tegra->usbphy[i]->otg, &tegra->hcd->self); in tegra_xusb_init_usb_phy()
1524 * usb-phy is optional, continue if its not available. in tegra_xusb_init_usb_phy()
1526 tegra->usbphy[i] = NULL; in tegra_xusb_init_usb_phy()
1537 cancel_work_sync(&tegra->id_work); in tegra_xusb_deinit_usb_phy()
1539 for (i = 0; i < tegra->num_usb_phys; i++) in tegra_xusb_deinit_usb_phy()
1540 if (tegra->usbphy[i]) in tegra_xusb_deinit_usb_phy()
1541 otg_set_host(tegra->usbphy[i]->otg, NULL); in tegra_xusb_deinit_usb_phy()
1548 if (tegra->soc->max_num_wakes == 0) in tegra_xusb_setup_wakeup()
1551 tegra->wake_irqs = devm_kcalloc(tegra->dev, in tegra_xusb_setup_wakeup()
1552 tegra->soc->max_num_wakes, in tegra_xusb_setup_wakeup()
1553 sizeof(*tegra->wake_irqs), GFP_KERNEL); in tegra_xusb_setup_wakeup()
1554 if (!tegra->wake_irqs) in tegra_xusb_setup_wakeup()
1555 return -ENOMEM; in tegra_xusb_setup_wakeup()
1559 * to utilize all wake-up events supported for a given device. The USB host can operate in tegra_xusb_setup_wakeup()
1560 * even if wake-up events are not defined or fail to be configured. Therefore, we only in tegra_xusb_setup_wakeup()
1561 * return critical errors, such as -ENOMEM. in tegra_xusb_setup_wakeup()
1563 for (i = 0; i < tegra->soc->max_num_wakes; i++) { in tegra_xusb_setup_wakeup()
1566 tegra->wake_irqs[i] = platform_get_irq(pdev, i + WAKE_IRQ_START_INDEX); in tegra_xusb_setup_wakeup()
1567 if (tegra->wake_irqs[i] < 0) in tegra_xusb_setup_wakeup()
1570 data = irq_get_irq_data(tegra->wake_irqs[i]); in tegra_xusb_setup_wakeup()
1572 dev_warn(tegra->dev, "get wake event %d irq data fail\n", i); in tegra_xusb_setup_wakeup()
1573 irq_dispose_mapping(tegra->wake_irqs[i]); in tegra_xusb_setup_wakeup()
1577 irq_set_irq_type(tegra->wake_irqs[i], irqd_get_trigger_type(data)); in tegra_xusb_setup_wakeup()
1580 tegra->num_wakes = i; in tegra_xusb_setup_wakeup()
1581 dev_dbg(tegra->dev, "setup %d wake events\n", tegra->num_wakes); in tegra_xusb_setup_wakeup()
1590 for (i = 0; i < tegra->num_wakes; i++) in tegra_xusb_dispose_wake()
1591 irq_dispose_mapping(tegra->wake_irqs[i]); in tegra_xusb_dispose_wake()
1593 tegra->num_wakes = 0; in tegra_xusb_dispose_wake()
1608 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_xusb_probe()
1610 return -ENOMEM; in tegra_xusb_probe()
1612 tegra->soc = of_device_get_match_data(&pdev->dev); in tegra_xusb_probe()
1613 mutex_init(&tegra->lock); in tegra_xusb_probe()
1614 tegra->dev = &pdev->dev; in tegra_xusb_probe()
1620 tegra->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &regs); in tegra_xusb_probe()
1621 if (IS_ERR(tegra->regs)) in tegra_xusb_probe()
1622 return PTR_ERR(tegra->regs); in tegra_xusb_probe()
1624 tegra->fpci_base = devm_platform_ioremap_resource(pdev, 1); in tegra_xusb_probe()
1625 if (IS_ERR(tegra->fpci_base)) in tegra_xusb_probe()
1626 return PTR_ERR(tegra->fpci_base); in tegra_xusb_probe()
1628 if (tegra->soc->has_ipfs) { in tegra_xusb_probe()
1629 tegra->ipfs_base = devm_platform_ioremap_resource(pdev, 2); in tegra_xusb_probe()
1630 if (IS_ERR(tegra->ipfs_base)) in tegra_xusb_probe()
1631 return PTR_ERR(tegra->ipfs_base); in tegra_xusb_probe()
1632 } else if (tegra->soc->has_bar2) { in tegra_xusb_probe()
1633 tegra->bar2_base = devm_platform_get_and_ioremap_resource(pdev, 2, &tegra->bar2); in tegra_xusb_probe()
1634 if (IS_ERR(tegra->bar2_base)) in tegra_xusb_probe()
1635 return PTR_ERR(tegra->bar2_base); in tegra_xusb_probe()
1638 tegra->xhci_irq = platform_get_irq(pdev, 0); in tegra_xusb_probe()
1639 if (tegra->xhci_irq < 0) in tegra_xusb_probe()
1640 return tegra->xhci_irq; in tegra_xusb_probe()
1642 tegra->mbox_irq = platform_get_irq(pdev, 1); in tegra_xusb_probe()
1643 if (tegra->mbox_irq < 0) in tegra_xusb_probe()
1644 return tegra->mbox_irq; in tegra_xusb_probe()
1650 tegra->padctl = tegra_xusb_padctl_get(&pdev->dev); in tegra_xusb_probe()
1651 if (IS_ERR(tegra->padctl)) { in tegra_xusb_probe()
1652 err = PTR_ERR(tegra->padctl); in tegra_xusb_probe()
1656 np = of_parse_phandle(pdev->dev.of_node, "nvidia,xusb-padctl", 0); in tegra_xusb_probe()
1658 err = -ENODEV; in tegra_xusb_probe()
1662 tegra->padctl_irq = of_irq_get(np, 0); in tegra_xusb_probe()
1663 if (tegra->padctl_irq == -EPROBE_DEFER) { in tegra_xusb_probe()
1664 err = tegra->padctl_irq; in tegra_xusb_probe()
1666 } else if (tegra->padctl_irq <= 0) { in tegra_xusb_probe()
1667 /* Older device-trees don't have padctrl interrupt */ in tegra_xusb_probe()
1668 tegra->padctl_irq = 0; in tegra_xusb_probe()
1669 dev_dbg(&pdev->dev, in tegra_xusb_probe()
1673 tegra->host_clk = devm_clk_get(&pdev->dev, "xusb_host"); in tegra_xusb_probe()
1674 if (IS_ERR(tegra->host_clk)) { in tegra_xusb_probe()
1675 err = PTR_ERR(tegra->host_clk); in tegra_xusb_probe()
1676 dev_err(&pdev->dev, "failed to get xusb_host: %d\n", err); in tegra_xusb_probe()
1680 tegra->falcon_clk = devm_clk_get(&pdev->dev, "xusb_falcon_src"); in tegra_xusb_probe()
1681 if (IS_ERR(tegra->falcon_clk)) { in tegra_xusb_probe()
1682 err = PTR_ERR(tegra->falcon_clk); in tegra_xusb_probe()
1683 dev_err(&pdev->dev, "failed to get xusb_falcon_src: %d\n", err); in tegra_xusb_probe()
1687 tegra->ss_clk = devm_clk_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1688 if (IS_ERR(tegra->ss_clk)) { in tegra_xusb_probe()
1689 err = PTR_ERR(tegra->ss_clk); in tegra_xusb_probe()
1690 dev_err(&pdev->dev, "failed to get xusb_ss: %d\n", err); in tegra_xusb_probe()
1694 tegra->ss_src_clk = devm_clk_get(&pdev->dev, "xusb_ss_src"); in tegra_xusb_probe()
1695 if (IS_ERR(tegra->ss_src_clk)) { in tegra_xusb_probe()
1696 err = PTR_ERR(tegra->ss_src_clk); in tegra_xusb_probe()
1697 dev_err(&pdev->dev, "failed to get xusb_ss_src: %d\n", err); in tegra_xusb_probe()
1701 tegra->hs_src_clk = devm_clk_get(&pdev->dev, "xusb_hs_src"); in tegra_xusb_probe()
1702 if (IS_ERR(tegra->hs_src_clk)) { in tegra_xusb_probe()
1703 err = PTR_ERR(tegra->hs_src_clk); in tegra_xusb_probe()
1704 dev_err(&pdev->dev, "failed to get xusb_hs_src: %d\n", err); in tegra_xusb_probe()
1708 tegra->fs_src_clk = devm_clk_get(&pdev->dev, "xusb_fs_src"); in tegra_xusb_probe()
1709 if (IS_ERR(tegra->fs_src_clk)) { in tegra_xusb_probe()
1710 err = PTR_ERR(tegra->fs_src_clk); in tegra_xusb_probe()
1711 dev_err(&pdev->dev, "failed to get xusb_fs_src: %d\n", err); in tegra_xusb_probe()
1715 tegra->pll_u_480m = devm_clk_get(&pdev->dev, "pll_u_480m"); in tegra_xusb_probe()
1716 if (IS_ERR(tegra->pll_u_480m)) { in tegra_xusb_probe()
1717 err = PTR_ERR(tegra->pll_u_480m); in tegra_xusb_probe()
1718 dev_err(&pdev->dev, "failed to get pll_u_480m: %d\n", err); in tegra_xusb_probe()
1722 tegra->clk_m = devm_clk_get(&pdev->dev, "clk_m"); in tegra_xusb_probe()
1723 if (IS_ERR(tegra->clk_m)) { in tegra_xusb_probe()
1724 err = PTR_ERR(tegra->clk_m); in tegra_xusb_probe()
1725 dev_err(&pdev->dev, "failed to get clk_m: %d\n", err); in tegra_xusb_probe()
1729 tegra->pll_e = devm_clk_get(&pdev->dev, "pll_e"); in tegra_xusb_probe()
1730 if (IS_ERR(tegra->pll_e)) { in tegra_xusb_probe()
1731 err = PTR_ERR(tegra->pll_e); in tegra_xusb_probe()
1732 dev_err(&pdev->dev, "failed to get pll_e: %d\n", err); in tegra_xusb_probe()
1736 if (!of_property_present(pdev->dev.of_node, "power-domains")) { in tegra_xusb_probe()
1737 tegra->host_rst = devm_reset_control_get(&pdev->dev, in tegra_xusb_probe()
1739 if (IS_ERR(tegra->host_rst)) { in tegra_xusb_probe()
1740 err = PTR_ERR(tegra->host_rst); in tegra_xusb_probe()
1741 dev_err(&pdev->dev, in tegra_xusb_probe()
1746 tegra->ss_rst = devm_reset_control_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1747 if (IS_ERR(tegra->ss_rst)) { in tegra_xusb_probe()
1748 err = PTR_ERR(tegra->ss_rst); in tegra_xusb_probe()
1749 dev_err(&pdev->dev, "failed to get xusb_ss reset: %d\n", in tegra_xusb_probe()
1754 err = tegra_xusb_powerdomain_init(&pdev->dev, tegra); in tegra_xusb_probe()
1759 tegra->supplies = devm_kcalloc(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1760 sizeof(*tegra->supplies), GFP_KERNEL); in tegra_xusb_probe()
1761 if (!tegra->supplies) { in tegra_xusb_probe()
1762 err = -ENOMEM; in tegra_xusb_probe()
1766 regulator_bulk_set_supply_names(tegra->supplies, in tegra_xusb_probe()
1767 tegra->soc->supply_names, in tegra_xusb_probe()
1768 tegra->soc->num_supplies); in tegra_xusb_probe()
1770 err = devm_regulator_bulk_get(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1771 tegra->supplies); in tegra_xusb_probe()
1773 dev_err(&pdev->dev, "failed to get regulators: %d\n", err); in tegra_xusb_probe()
1777 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1778 if (!strncmp(tegra->soc->phy_types[i].name, "usb2", 4)) in tegra_xusb_probe()
1779 tegra->num_usb_phys = tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1780 tegra->num_phys += tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1783 tegra->phys = devm_kcalloc(&pdev->dev, tegra->num_phys, in tegra_xusb_probe()
1784 sizeof(*tegra->phys), GFP_KERNEL); in tegra_xusb_probe()
1785 if (!tegra->phys) { in tegra_xusb_probe()
1786 err = -ENOMEM; in tegra_xusb_probe()
1790 for (i = 0, k = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1793 for (j = 0; j < tegra->soc->phy_types[i].num; j++) { in tegra_xusb_probe()
1794 snprintf(prop, sizeof(prop), "%s-%d", in tegra_xusb_probe()
1795 tegra->soc->phy_types[i].name, j); in tegra_xusb_probe()
1797 phy = devm_phy_optional_get(&pdev->dev, prop); in tegra_xusb_probe()
1799 dev_err(&pdev->dev, in tegra_xusb_probe()
1806 tegra->phys[k++] = phy; in tegra_xusb_probe()
1810 tegra->hcd = usb_create_hcd(&tegra_xhci_hc_driver, &pdev->dev, in tegra_xusb_probe()
1811 dev_name(&pdev->dev)); in tegra_xusb_probe()
1812 if (!tegra->hcd) { in tegra_xusb_probe()
1813 err = -ENOMEM; in tegra_xusb_probe()
1817 tegra->hcd->skip_phy_initialization = 1; in tegra_xusb_probe()
1818 tegra->hcd->regs = tegra->regs; in tegra_xusb_probe()
1819 tegra->hcd->rsrc_start = regs->start; in tegra_xusb_probe()
1820 tegra->hcd->rsrc_len = resource_size(regs); in tegra_xusb_probe()
1830 dev_err(tegra->dev, "failed to enable clocks: %d\n", err); in tegra_xusb_probe()
1834 err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_probe()
1836 dev_err(tegra->dev, "failed to enable regulators: %d\n", err); in tegra_xusb_probe()
1842 dev_err(&pdev->dev, "failed to enable PHYs: %d\n", err); in tegra_xusb_probe()
1850 err = dma_set_mask_and_coherent(tegra->dev, DMA_BIT_MASK(40)); in tegra_xusb_probe()
1852 dev_err(&pdev->dev, "failed to set DMA mask: %d\n", err); in tegra_xusb_probe()
1856 if (tegra->soc->firmware) { in tegra_xusb_probe()
1859 dev_err(&pdev->dev, in tegra_xusb_probe()
1873 dev_err(&pdev->dev, "failed to load firmware: %d\n", err); in tegra_xusb_probe()
1877 err = usb_add_hcd(tegra->hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1879 dev_err(&pdev->dev, "failed to add USB HCD: %d\n", err); in tegra_xusb_probe()
1883 device_wakeup_enable(tegra->hcd->self.controller); in tegra_xusb_probe()
1885 xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_probe()
1887 xhci->shared_hcd = usb_create_shared_hcd(&tegra_xhci_hc_driver, in tegra_xusb_probe()
1888 &pdev->dev, in tegra_xusb_probe()
1889 dev_name(&pdev->dev), in tegra_xusb_probe()
1890 tegra->hcd); in tegra_xusb_probe()
1891 if (!xhci->shared_hcd) { in tegra_xusb_probe()
1892 dev_err(&pdev->dev, "failed to create shared HCD\n"); in tegra_xusb_probe()
1893 err = -ENOMEM; in tegra_xusb_probe()
1897 if (HCC_MAX_PSA(xhci->hcc_params) >= 4) in tegra_xusb_probe()
1898 xhci->shared_hcd->can_do_streams = 1; in tegra_xusb_probe()
1900 err = usb_add_hcd(xhci->shared_hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1902 dev_err(&pdev->dev, "failed to add shared HCD: %d\n", err); in tegra_xusb_probe()
1906 err = devm_request_threaded_irq(&pdev->dev, tegra->mbox_irq, in tegra_xusb_probe()
1909 dev_name(&pdev->dev), tegra); in tegra_xusb_probe()
1911 dev_err(&pdev->dev, "failed to request IRQ: %d\n", err); in tegra_xusb_probe()
1915 if (tegra->padctl_irq) { in tegra_xusb_probe()
1916 err = devm_request_threaded_irq(&pdev->dev, tegra->padctl_irq, in tegra_xusb_probe()
1918 IRQF_ONESHOT, dev_name(&pdev->dev), in tegra_xusb_probe()
1921 dev_err(&pdev->dev, "failed to request padctl IRQ: %d\n", err); in tegra_xusb_probe()
1928 dev_err(&pdev->dev, "failed to enable messages: %d\n", err); in tegra_xusb_probe()
1934 dev_err(&pdev->dev, "failed to init USB PHY: %d\n", err); in tegra_xusb_probe()
1939 device_init_wakeup(&tegra->hcd->self.root_hub->dev, true); in tegra_xusb_probe()
1940 device_init_wakeup(&xhci->shared_hcd->self.root_hub->dev, true); in tegra_xusb_probe()
1942 pm_runtime_use_autosuspend(tegra->dev); in tegra_xusb_probe()
1943 pm_runtime_set_autosuspend_delay(tegra->dev, 2000); in tegra_xusb_probe()
1944 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_probe()
1945 pm_runtime_set_active(tegra->dev); in tegra_xusb_probe()
1947 if (tegra->padctl_irq) { in tegra_xusb_probe()
1948 device_init_wakeup(tegra->dev, true); in tegra_xusb_probe()
1949 pm_runtime_enable(tegra->dev); in tegra_xusb_probe()
1955 usb_remove_hcd(xhci->shared_hcd); in tegra_xusb_probe()
1957 usb_put_hcd(xhci->shared_hcd); in tegra_xusb_probe()
1959 usb_remove_hcd(tegra->hcd); in tegra_xusb_probe()
1963 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_probe()
1964 tegra->fw.phys); in tegra_xusb_probe()
1968 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_probe()
1972 usb_put_hcd(tegra->hcd); in tegra_xusb_probe()
1974 tegra_xusb_powerdomain_remove(&pdev->dev, tegra); in tegra_xusb_probe()
1977 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_probe()
1986 tegra_xusb_powerdomain_remove(tegra->dev, tegra); in tegra_xusb_disable()
1989 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_disable()
1995 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_remove()
1999 pm_runtime_get_sync(&pdev->dev); in tegra_xusb_remove()
2000 usb_remove_hcd(xhci->shared_hcd); in tegra_xusb_remove()
2001 usb_put_hcd(xhci->shared_hcd); in tegra_xusb_remove()
2002 xhci->shared_hcd = NULL; in tegra_xusb_remove()
2003 usb_remove_hcd(tegra->hcd); in tegra_xusb_remove()
2004 usb_put_hcd(tegra->hcd); in tegra_xusb_remove()
2006 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_remove()
2007 tegra->fw.phys); in tegra_xusb_remove()
2009 if (tegra->padctl_irq) in tegra_xusb_remove()
2010 pm_runtime_disable(&pdev->dev); in tegra_xusb_remove()
2014 pm_runtime_put(&pdev->dev); in tegra_xusb_remove()
2017 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_remove()
2024 pm_runtime_get_sync(&pdev->dev); in tegra_xusb_shutdown()
2025 disable_irq(tegra->xhci_irq); in tegra_xusb_shutdown()
2026 xhci_shutdown(tegra->hcd); in tegra_xusb_shutdown()
2032 struct device *dev = hub->hcd->self.controller; in xhci_hub_ports_suspended()
2037 for (i = 0; i < hub->num_ports; i++) { in xhci_hub_ports_suspended()
2038 value = xhci_portsc_readl(hub->ports[i]); in xhci_hub_ports_suspended()
2043 dev_info(dev, "%u-%u isn't suspended: %#010x\n", in xhci_hub_ports_suspended()
2044 hub->hcd->self.busnum, i + 1, value); in xhci_hub_ports_suspended()
2054 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_check_ports()
2055 struct xhci_bus_state *bus_state = &xhci->usb2_rhub.bus_state; in tegra_xusb_check_ports()
2059 if (bus_state->bus_suspended) { in tegra_xusb_check_ports()
2066 spin_lock_irqsave(&xhci->lock, flags); in tegra_xusb_check_ports()
2068 if (!xhci_hub_ports_suspended(&xhci->usb2_rhub) || in tegra_xusb_check_ports()
2069 !xhci_hub_ports_suspended(&xhci->usb3_rhub)) in tegra_xusb_check_ports()
2070 err = -EBUSY; in tegra_xusb_check_ports()
2072 spin_unlock_irqrestore(&xhci->lock, flags); in tegra_xusb_check_ports()
2079 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_save_context()
2080 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_save_context()
2083 if (soc->ipfs.num_offsets > 0) { in tegra_xusb_save_context()
2084 for (i = 0; i < soc->ipfs.num_offsets; i++) in tegra_xusb_save_context()
2085 ctx->ipfs[i] = ipfs_readl(tegra, soc->ipfs.offsets[i]); in tegra_xusb_save_context()
2088 if (soc->fpci.num_offsets > 0) { in tegra_xusb_save_context()
2089 for (i = 0; i < soc->fpci.num_offsets; i++) in tegra_xusb_save_context()
2090 ctx->fpci[i] = fpci_readl(tegra, soc->fpci.offsets[i]); in tegra_xusb_save_context()
2096 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_restore_context()
2097 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_restore_context()
2100 if (soc->fpci.num_offsets > 0) { in tegra_xusb_restore_context()
2101 for (i = 0; i < soc->fpci.num_offsets; i++) in tegra_xusb_restore_context()
2102 fpci_writel(tegra, ctx->fpci[i], soc->fpci.offsets[i]); in tegra_xusb_restore_context()
2105 if (soc->ipfs.num_offsets > 0) { in tegra_xusb_restore_context()
2106 for (i = 0; i < soc->ipfs.num_offsets; i++) in tegra_xusb_restore_context()
2107 ipfs_writel(tegra, ctx->ipfs[i], soc->ipfs.offsets[i]); in tegra_xusb_restore_context()
2130 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_enable_phy_sleepwalk_wake()
2131 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_enable_phy_sleepwalk_wake()
2139 for (i = 0, k = 0; i < tegra->soc->num_types; i++) { in tegra_xhci_enable_phy_sleepwalk_wake()
2140 if (strcmp(tegra->soc->phy_types[i].name, "usb3") == 0) in tegra_xhci_enable_phy_sleepwalk_wake()
2141 rhub = &xhci->usb3_rhub; in tegra_xhci_enable_phy_sleepwalk_wake()
2143 rhub = &xhci->usb2_rhub; in tegra_xhci_enable_phy_sleepwalk_wake()
2145 if (strcmp(tegra->soc->phy_types[i].name, "hsic") == 0) in tegra_xhci_enable_phy_sleepwalk_wake()
2146 offset = tegra->soc->ports.usb2.count; in tegra_xhci_enable_phy_sleepwalk_wake()
2150 for (j = 0; j < tegra->soc->phy_types[i].num; j++) { in tegra_xhci_enable_phy_sleepwalk_wake()
2151 phy = tegra->phys[k++]; in tegra_xhci_enable_phy_sleepwalk_wake()
2158 if (index >= rhub->num_ports) in tegra_xhci_enable_phy_sleepwalk_wake()
2164 portsc = xhci_portsc_readl(rhub->ports[index]); in tegra_xhci_enable_phy_sleepwalk_wake()
2174 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_disable_phy_wake()
2177 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xhci_disable_phy_wake()
2187 for (i = 0; i < tegra->num_phys; i++) { in tegra_xhci_disable_phy_wake()
2188 if (!tegra->phys[i]) in tegra_xhci_disable_phy_wake()
2191 if (tegra_xusb_padctl_remote_wake_detected(padctl, tegra->phys[i])) in tegra_xhci_disable_phy_wake()
2192 dev_dbg(tegra->dev, "%pOF remote wake detected\n", in tegra_xhci_disable_phy_wake()
2193 tegra->phys[i]->dev.of_node); in tegra_xhci_disable_phy_wake()
2195 tegra_xusb_padctl_disable_phy_wake(padctl, tegra->phys[i]); in tegra_xhci_disable_phy_wake()
2201 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xhci_disable_phy_sleepwalk()
2204 for (i = 0; i < tegra->num_phys; i++) { in tegra_xhci_disable_phy_sleepwalk()
2205 if (!tegra->phys[i]) in tegra_xhci_disable_phy_sleepwalk()
2208 tegra_xusb_padctl_disable_phy_sleepwalk(padctl, tegra->phys[i]); in tegra_xhci_disable_phy_sleepwalk()
2217 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xhci_program_utmi_power_lp0_exit()
2218 if (strcmp(tegra->soc->phy_types[i].name, "usb2") == 0) in tegra_xhci_program_utmi_power_lp0_exit()
2222 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xhci_program_utmi_power_lp0_exit()
2227 if (tegra->lp0_utmi_pad_mask & BIT(i)) in tegra_xhci_program_utmi_power_lp0_exit()
2236 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_enter_elpg()
2237 struct device *dev = tegra->dev; in tegra_xusb_enter_elpg()
2246 usbcmd = readl(&xhci->op_regs->command); in tegra_xusb_enter_elpg()
2248 writel(usbcmd, &xhci->op_regs->command); in tegra_xusb_enter_elpg()
2252 dev_err(tegra->dev, "not all ports suspended: %d\n", err); in tegra_xusb_enter_elpg()
2256 for (i = 0; i < xhci->usb2_rhub.num_ports; i++) { in tegra_xusb_enter_elpg()
2257 if (!xhci->usb2_rhub.ports[i]) in tegra_xusb_enter_elpg()
2259 portsc = xhci_portsc_readl(xhci->usb2_rhub.ports[i]); in tegra_xusb_enter_elpg()
2260 tegra->lp0_utmi_pad_mask &= ~BIT(i); in tegra_xusb_enter_elpg()
2262 tegra->lp0_utmi_pad_mask |= BIT(i); in tegra_xusb_enter_elpg()
2267 dev_err(tegra->dev, "failed to suspend XHCI: %d\n", err); in tegra_xusb_enter_elpg()
2278 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_enter_elpg()
2279 if (!tegra->phys[i]) in tegra_xusb_enter_elpg()
2282 phy_power_off(tegra->phys[i]); in tegra_xusb_enter_elpg()
2284 phy_exit(tegra->phys[i]); in tegra_xusb_enter_elpg()
2291 dev_dbg(tegra->dev, "entering ELPG done\n"); in tegra_xusb_enter_elpg()
2293 usbcmd = readl(&xhci->op_regs->command); in tegra_xusb_enter_elpg()
2295 writel(usbcmd, &xhci->op_regs->command); in tegra_xusb_enter_elpg()
2297 dev_dbg(tegra->dev, "entering ELPG failed\n"); in tegra_xusb_enter_elpg()
2298 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_enter_elpg()
2306 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_exit_elpg()
2307 struct device *dev = tegra->dev; in tegra_xusb_exit_elpg()
2314 pm_runtime_mark_last_busy(tegra->dev); in tegra_xusb_exit_elpg()
2318 dev_err(tegra->dev, "failed to enable clocks: %d\n", err); in tegra_xusb_exit_elpg()
2329 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_exit_elpg()
2330 if (!tegra->phys[i]) in tegra_xusb_exit_elpg()
2334 phy_init(tegra->phys[i]); in tegra_xusb_exit_elpg()
2336 phy_power_on(tegra->phys[i]); in tegra_xusb_exit_elpg()
2338 if (tegra->suspended) in tegra_xusb_exit_elpg()
2346 dev_err(tegra->dev, "failed to load firmware: %d\n", err); in tegra_xusb_exit_elpg()
2352 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in tegra_xusb_exit_elpg()
2361 dev_err(tegra->dev, "failed to resume XHCI: %d\n", err); in tegra_xusb_exit_elpg()
2365 usbcmd = readl(&xhci->op_regs->command); in tegra_xusb_exit_elpg()
2367 writel(usbcmd, &xhci->op_regs->command); in tegra_xusb_exit_elpg()
2372 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_exit_elpg()
2373 if (!tegra->phys[i]) in tegra_xusb_exit_elpg()
2376 phy_power_off(tegra->phys[i]); in tegra_xusb_exit_elpg()
2378 phy_exit(tegra->phys[i]); in tegra_xusb_exit_elpg()
2397 synchronize_irq(tegra->mbox_irq); in tegra_xusb_suspend()
2399 mutex_lock(&tegra->lock); in tegra_xusb_suspend()
2420 tegra->suspended = true; in tegra_xusb_suspend()
2426 if (enable_irq_wake(tegra->padctl_irq)) in tegra_xusb_suspend()
2429 for (i = 0; i < tegra->num_wakes; i++) in tegra_xusb_suspend()
2430 enable_irq_wake(tegra->wake_irqs[i]); in tegra_xusb_suspend()
2434 mutex_unlock(&tegra->lock); in tegra_xusb_suspend()
2444 mutex_lock(&tegra->lock); in tegra_xusb_resume()
2446 if (!tegra->suspended) { in tegra_xusb_resume()
2447 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2453 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2460 if (disable_irq_wake(tegra->padctl_irq)) in tegra_xusb_resume()
2463 for (i = 0; i < tegra->num_wakes; i++) in tegra_xusb_resume()
2464 disable_irq_wake(tegra->wake_irqs[i]); in tegra_xusb_resume()
2466 tegra->suspended = false; in tegra_xusb_resume()
2467 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
2480 synchronize_irq(tegra->mbox_irq); in tegra_xusb_runtime_suspend()
2481 mutex_lock(&tegra->lock); in tegra_xusb_runtime_suspend()
2483 mutex_unlock(&tegra->lock); in tegra_xusb_runtime_suspend()
2493 mutex_lock(&tegra->lock); in tegra_xusb_runtime_resume()
2495 mutex_unlock(&tegra->lock); in tegra_xusb_runtime_resume()
2507 "avddio-pex",
2508 "dvddio-pex",
2509 "avdd-usb",
2510 "hvdd-usb-ss",
2514 { .name = "usb3", .num = 2, },
2515 { .name = "usb2", .num = 3, },
2516 { .name = "hsic", .num = 2, },
2569 .ports = {
2589 "dvddio-pex",
2590 "hvddio-pex",
2591 "avdd-usb",
2595 { .name = "usb3", .num = 4, },
2596 { .name = "usb2", .num = 4, },
2597 { .name = "hsic", .num = 1, },
2607 .ports = {
2631 { .name = "usb3", .num = 3, },
2632 { .name = "usb2", .num = 3, },
2633 { .name = "hsic", .num = 1, },
2650 .ports = {
2673 { .name = "usb3", .num = 4, },
2674 { .name = "usb2", .num = 4, },
2684 .ports = {
2717 .ports = {
2737 { .compatible = "nvidia,tegra124-xusb", .data = &tegra124_soc },
2738 { .compatible = "nvidia,tegra210-xusb", .data = &tegra210_soc },
2739 { .compatible = "nvidia,tegra186-xusb", .data = &tegra186_soc },
2740 { .compatible = "nvidia,tegra194-xusb", .data = &tegra194_soc },
2741 { .compatible = "nvidia,tegra234-xusb", .data = &tegra234_soc },
2751 .name = "tegra-xusb",
2761 if (tegra && tegra->soc->lpm_support) in tegra_xhci_quirks()
2762 xhci->quirks |= XHCI_LPM_SUPPORT; in tegra_xhci_quirks()
2773 struct tegra_xusb *tegra = dev_get_drvdata(hcd->self.controller); in tegra_xhci_hub_control()
2777 int port = (index & 0xff) - 1; in tegra_xhci_hub_control()
2779 struct xhci_port **ports; in tegra_xhci_hub_control() local
2784 rhub = &xhci->usb2_rhub; in tegra_xhci_hub_control()
2785 bus_state = &rhub->bus_state; in tegra_xhci_hub_control()
2786 if (bus_state->resuming_ports && hcd->speed == HCD_USB2) { in tegra_xhci_hub_control()
2787 ports = rhub->ports; in tegra_xhci_hub_control()
2788 i = rhub->num_ports; in tegra_xhci_hub_control()
2789 while (i--) { in tegra_xhci_hub_control()
2790 if (!test_bit(i, &bus_state->resuming_ports)) in tegra_xhci_hub_control()
2792 portsc = xhci_portsc_readl(ports[i]); in tegra_xhci_hub_control()
2799 if (hcd->speed == HCD_USB2) { in tegra_xhci_hub_control()
2802 if (!index || index > rhub->num_ports) in tegra_xhci_hub_control()
2803 return -EPIPE; in tegra_xhci_hub_control()
2807 if (!index || index > rhub->num_ports) in tegra_xhci_hub_control()
2808 return -EPIPE; in tegra_xhci_hub_control()
2809 ports = rhub->ports; in tegra_xhci_hub_control()
2810 portsc = xhci_portsc_readl(ports[port]); in tegra_xhci_hub_control()
2820 if (hcd->speed == HCD_USB2) { in tegra_xhci_hub_control()
2824 if (!((hcd->self.otg_port == (port + 1)) && hcd->self.b_hnp_enable)) in tegra_xhci_hub_control()
2828 ports = rhub->ports; in tegra_xhci_hub_control()
2829 portsc = xhci_portsc_readl(ports[port]); in tegra_xhci_hub_control()
2834 if (!((hcd->self.otg_port == (port + 1)) && hcd->self.b_hnp_enable)) in tegra_xhci_hub_control()
2865 MODULE_DESCRIPTION("NVIDIA Tegra XUSB xHCI host-controller driver");