Lines Matching +full:num +full:- +full:ports
1 // SPDX-License-Identifier: GPL-2.0
11 #include <linux/dma-mapping.h>
168 unsigned int num; member
203 } ports; member
280 return readl(tegra->fpci_base + offset); in fpci_readl()
286 writel(value, tegra->fpci_base + offset); in fpci_writel()
291 return readl(tegra->ipfs_base + offset); in ipfs_readl()
297 writel(value, tegra->ipfs_base + offset); in ipfs_writel()
324 struct clk *clk = tegra->ss_src_clk; in tegra_xusb_set_ss_clk()
338 new_parent_rate = clk_get_rate(tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
345 err = clk_set_parent(clk, tegra->pll_u_480m); in tegra_xusb_set_ss_clk()
361 err = clk_set_parent(clk, tegra->clk_m); in tegra_xusb_set_ss_clk()
372 dev_err(tegra->dev, "Invalid SS rate: %lu Hz\n", rate); in tegra_xusb_set_ss_clk()
373 return -EINVAL; in tegra_xusb_set_ss_clk()
377 dev_err(tegra->dev, "SS clock doesn't match requested rate\n"); in tegra_xusb_set_ss_clk()
378 return -EINVAL; in tegra_xusb_set_ss_clk()
387 return (value >> start) & ((1 << count) - 1); in extract_field()
425 return (msg->cmd & CMD_TYPE_MASK) << CMD_TYPE_SHIFT | in tegra_xusb_mbox_pack()
426 (msg->data & CMD_DATA_MASK) << CMD_DATA_SHIFT; in tegra_xusb_mbox_pack()
431 msg->cmd = (value >> CMD_TYPE_SHIFT) & CMD_TYPE_MASK; in tegra_xusb_mbox_unpack()
432 msg->data = (value >> CMD_DATA_SHIFT) & CMD_DATA_MASK; in tegra_xusb_mbox_unpack()
458 if (!(msg->cmd == MBOX_CMD_ACK || msg->cmd == MBOX_CMD_NAK)) { in tegra_xusb_mbox_send()
459 value = fpci_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
461 dev_err(tegra->dev, "mailbox is busy\n"); in tegra_xusb_mbox_send()
462 return -EBUSY; in tegra_xusb_mbox_send()
465 fpci_writel(tegra, MBOX_OWNER_SW, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
467 value = fpci_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
469 dev_err(tegra->dev, "failed to acquire mailbox\n"); in tegra_xusb_mbox_send()
470 return -EBUSY; in tegra_xusb_mbox_send()
477 fpci_writel(tegra, value, tegra->soc->mbox.data_in); in tegra_xusb_mbox_send()
479 value = fpci_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
481 fpci_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_send()
487 value = fpci_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
495 value = fpci_readl(tegra, tegra->soc->mbox.owner); in tegra_xusb_mbox_send()
498 return -ETIMEDOUT; in tegra_xusb_mbox_send()
514 dev_err(tegra->dev, "controller firmware hang\n"); in tegra_xusb_mbox_irq()
522 struct tegra_xusb_padctl *padctl = tegra->padctl; in tegra_xusb_mbox_handle()
523 const struct tegra_xusb_soc *soc = tegra->soc; in tegra_xusb_mbox_handle()
524 struct device *dev = tegra->dev; in tegra_xusb_mbox_handle()
533 switch (msg->cmd) { in tegra_xusb_mbox_handle()
536 rsp.data = clk_get_rate(tegra->falcon_clk) / 1000; in tegra_xusb_mbox_handle()
537 if (rsp.data != msg->data) in tegra_xusb_mbox_handle()
546 if (tegra->soc->scale_ss_clock) { in tegra_xusb_mbox_handle()
547 err = tegra_xusb_set_ss_clk(tegra, msg->data * 1000); in tegra_xusb_mbox_handle()
553 rsp.data = clk_get_rate(tegra->ss_src_clk) / 1000; in tegra_xusb_mbox_handle()
556 rsp.data = msg->data; in tegra_xusb_mbox_handle()
570 err = tegra_xusb_padctl_usb3_save_context(padctl, msg->data); in tegra_xusb_mbox_handle()
573 msg->data, err); in tegra_xusb_mbox_handle()
579 rsp.data = msg->data; in tegra_xusb_mbox_handle()
584 if (msg->cmd == MBOX_CMD_STOP_HSIC_IDLE) in tegra_xusb_mbox_handle()
589 mask = extract_field(msg->data, 1 + soc->ports.hsic.offset, in tegra_xusb_mbox_handle()
590 soc->ports.hsic.count); in tegra_xusb_mbox_handle()
607 rsp.data = msg->data; in tegra_xusb_mbox_handle()
612 if (msg->cmd == MBOX_CMD_DISABLE_SS_LFPS_DETECTION) in tegra_xusb_mbox_handle()
617 mask = extract_field(msg->data, 1 + soc->ports.usb3.offset, in tegra_xusb_mbox_handle()
618 soc->ports.usb3.count); in tegra_xusb_mbox_handle()
620 for_each_set_bit(port, &mask, soc->ports.usb3.count) { in tegra_xusb_mbox_handle()
637 rsp.data = msg->data; in tegra_xusb_mbox_handle()
641 dev_warn(dev, "unknown message: %#x\n", msg->cmd); in tegra_xusb_mbox_handle()
660 mutex_lock(&tegra->lock); in tegra_xusb_mbox_thread()
662 value = fpci_readl(tegra, tegra->soc->mbox.data_out); in tegra_xusb_mbox_thread()
665 value = fpci_readl(tegra, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
667 fpci_writel(tegra, value, tegra->soc->mbox.cmd); in tegra_xusb_mbox_thread()
671 fpci_writel(tegra, MBOX_OWNER_NONE, tegra->soc->mbox.owner); in tegra_xusb_mbox_thread()
675 mutex_unlock(&tegra->lock); in tegra_xusb_mbox_thread()
681 u32 regs = tegra->hcd->rsrc_start; in tegra_xusb_config()
684 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
705 if (tegra->soc->has_ipfs) { in tegra_xusb_config()
720 err = clk_prepare_enable(tegra->pll_e); in tegra_xusb_clk_enable()
724 err = clk_prepare_enable(tegra->host_clk); in tegra_xusb_clk_enable()
728 err = clk_prepare_enable(tegra->ss_clk); in tegra_xusb_clk_enable()
732 err = clk_prepare_enable(tegra->falcon_clk); in tegra_xusb_clk_enable()
736 err = clk_prepare_enable(tegra->fs_src_clk); in tegra_xusb_clk_enable()
740 err = clk_prepare_enable(tegra->hs_src_clk); in tegra_xusb_clk_enable()
744 if (tegra->soc->scale_ss_clock) { in tegra_xusb_clk_enable()
753 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_enable()
755 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_enable()
757 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_enable()
759 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_enable()
761 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_enable()
763 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_enable()
769 clk_disable_unprepare(tegra->pll_e); in tegra_xusb_clk_disable()
770 clk_disable_unprepare(tegra->host_clk); in tegra_xusb_clk_disable()
771 clk_disable_unprepare(tegra->ss_clk); in tegra_xusb_clk_disable()
772 clk_disable_unprepare(tegra->falcon_clk); in tegra_xusb_clk_disable()
773 clk_disable_unprepare(tegra->fs_src_clk); in tegra_xusb_clk_disable()
774 clk_disable_unprepare(tegra->hs_src_clk); in tegra_xusb_clk_disable()
782 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_enable()
783 err = phy_init(tegra->phys[i]); in tegra_xusb_phy_enable()
787 err = phy_power_on(tegra->phys[i]); in tegra_xusb_phy_enable()
789 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
797 while (i--) { in tegra_xusb_phy_enable()
798 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_enable()
799 phy_exit(tegra->phys[i]); in tegra_xusb_phy_enable()
809 for (i = 0; i < tegra->num_phys; i++) { in tegra_xusb_phy_disable()
810 phy_power_off(tegra->phys[i]); in tegra_xusb_phy_disable()
811 phy_exit(tegra->phys[i]); in tegra_xusb_phy_disable()
819 regulator_bulk_disable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_runtime_suspend()
836 err = regulator_bulk_enable(tegra->soc->num_supplies, tegra->supplies); in tegra_xusb_runtime_resume()
852 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_init_context()
854 tegra->context.ipfs = devm_kcalloc(tegra->dev, soc->ipfs.num_offsets, in tegra_xusb_init_context()
856 if (!tegra->context.ipfs) in tegra_xusb_init_context()
857 return -ENOMEM; in tegra_xusb_init_context()
859 tegra->context.fpci = devm_kcalloc(tegra->dev, soc->fpci.num_offsets, in tegra_xusb_init_context()
861 if (!tegra->context.fpci) in tegra_xusb_init_context()
862 return -ENOMEM; in tegra_xusb_init_context()
879 err = request_firmware(&fw, tegra->soc->firmware, tegra->dev); in tegra_xusb_request_firmware()
881 dev_err(tegra->dev, "failed to request firmware: %d\n", err); in tegra_xusb_request_firmware()
886 header = (struct tegra_xusb_fw_header *)fw->data; in tegra_xusb_request_firmware()
887 tegra->fw.size = le32_to_cpu(header->fwimg_len); in tegra_xusb_request_firmware()
889 tegra->fw.virt = dma_alloc_coherent(tegra->dev, tegra->fw.size, in tegra_xusb_request_firmware()
890 &tegra->fw.phys, GFP_KERNEL); in tegra_xusb_request_firmware()
891 if (!tegra->fw.virt) { in tegra_xusb_request_firmware()
892 dev_err(tegra->dev, "failed to allocate memory for firmware\n"); in tegra_xusb_request_firmware()
894 return -ENOMEM; in tegra_xusb_request_firmware()
897 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_request_firmware()
898 memcpy(tegra->fw.virt, fw->data, tegra->fw.size); in tegra_xusb_request_firmware()
907 struct xhci_cap_regs __iomem *cap = tegra->regs; in tegra_xusb_load_firmware()
909 struct device *dev = tegra->dev; in tegra_xusb_load_firmware()
918 header = (struct tegra_xusb_fw_header *)tegra->fw.virt; in tegra_xusb_load_firmware()
919 op = tegra->regs + HC_LENGTH(readl(&cap->hc_capbase)); in tegra_xusb_load_firmware()
928 csb_writel(tegra, tegra->fw.size, XUSB_CSB_MP_ILOAD_ATTR); in tegra_xusb_load_firmware()
934 address = tegra->fw.phys + sizeof(*header); in tegra_xusb_load_firmware()
948 code_tag_blocks = DIV_ROUND_UP(le32_to_cpu(header->boot_codetag), in tegra_xusb_load_firmware()
950 code_size_blocks = DIV_ROUND_UP(le32_to_cpu(header->boot_codesize), in tegra_xusb_load_firmware()
964 /* Setup Falcon auto-fill. */ in tegra_xusb_load_firmware()
986 csb_writel(tegra, le32_to_cpu(header->boot_codetag), in tegra_xusb_load_firmware()
995 value = readl(&op->status); in tegra_xusb_load_firmware()
1002 value = readl(&op->status); in tegra_xusb_load_firmware()
1006 return -EIO; in tegra_xusb_load_firmware()
1009 timestamp = le32_to_cpu(header->fwimg_created_time); in tegra_xusb_load_firmware()
1012 dev_info(dev, "Firmware timestamp: %ld-%02d-%02d %02d:%02d:%02d UTC\n", in tegra_xusb_load_firmware()
1022 if (tegra->genpd_dl_ss) in tegra_xusb_powerdomain_remove()
1023 device_link_del(tegra->genpd_dl_ss); in tegra_xusb_powerdomain_remove()
1024 if (tegra->genpd_dl_host) in tegra_xusb_powerdomain_remove()
1025 device_link_del(tegra->genpd_dl_host); in tegra_xusb_powerdomain_remove()
1026 if (!IS_ERR_OR_NULL(tegra->genpd_dev_ss)) in tegra_xusb_powerdomain_remove()
1027 dev_pm_domain_detach(tegra->genpd_dev_ss, true); in tegra_xusb_powerdomain_remove()
1028 if (!IS_ERR_OR_NULL(tegra->genpd_dev_host)) in tegra_xusb_powerdomain_remove()
1029 dev_pm_domain_detach(tegra->genpd_dev_host, true); in tegra_xusb_powerdomain_remove()
1037 tegra->genpd_dev_host = dev_pm_domain_attach_by_name(dev, "xusb_host"); in tegra_xusb_powerdomain_init()
1038 if (IS_ERR(tegra->genpd_dev_host)) { in tegra_xusb_powerdomain_init()
1039 err = PTR_ERR(tegra->genpd_dev_host); in tegra_xusb_powerdomain_init()
1040 dev_err(dev, "failed to get host pm-domain: %d\n", err); in tegra_xusb_powerdomain_init()
1044 tegra->genpd_dev_ss = dev_pm_domain_attach_by_name(dev, "xusb_ss"); in tegra_xusb_powerdomain_init()
1045 if (IS_ERR(tegra->genpd_dev_ss)) { in tegra_xusb_powerdomain_init()
1046 err = PTR_ERR(tegra->genpd_dev_ss); in tegra_xusb_powerdomain_init()
1047 dev_err(dev, "failed to get superspeed pm-domain: %d\n", err); in tegra_xusb_powerdomain_init()
1051 tegra->genpd_dl_host = device_link_add(dev, tegra->genpd_dev_host, in tegra_xusb_powerdomain_init()
1054 if (!tegra->genpd_dl_host) { in tegra_xusb_powerdomain_init()
1056 return -ENODEV; in tegra_xusb_powerdomain_init()
1059 tegra->genpd_dl_ss = device_link_add(dev, tegra->genpd_dev_ss, in tegra_xusb_powerdomain_init()
1062 if (!tegra->genpd_dl_ss) { in tegra_xusb_powerdomain_init()
1064 return -ENODEV; in tegra_xusb_powerdomain_init()
1081 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in __tegra_xusb_enable_firmware_messages()
1090 mutex_lock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1092 mutex_unlock(&tegra->lock); in tegra_xusb_enable_firmware_messages()
1100 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_set_port_power()
1101 struct usb_hcd *hcd = main ? xhci->main_hcd : xhci->shared_hcd; in tegra_xhci_set_port_power()
1104 u16 wIndex = main ? tegra->otg_usb2_port + 1 : tegra->otg_usb3_port + 1; in tegra_xhci_set_port_power()
1109 dev_dbg(tegra->dev, "%s():%s %s port power\n", __func__, in tegra_xhci_set_port_power()
1112 hcd->driver->hub_control(hcd, typeReq, USB_PORT_FEAT_POWER, wIndex, in tegra_xhci_set_port_power()
1125 } while (--wait > 0); in tegra_xhci_set_port_power()
1128 dev_info(tegra->dev, "failed to %s %s PP %d\n", in tegra_xhci_set_port_power()
1138 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_get_phy()
1139 if (!strncmp(tegra->soc->phy_types[i].name, name, in tegra_xusb_get_phy()
1141 return tegra->phys[phy_count+port]; in tegra_xusb_get_phy()
1143 phy_count += tegra->soc->phy_types[i].num; in tegra_xusb_get_phy()
1153 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xhci_id_work()
1156 tegra->otg_usb2_port); in tegra_xhci_id_work()
1160 dev_dbg(tegra->dev, "host mode %s\n", tegra->host_mode ? "on" : "off"); in tegra_xhci_id_work()
1162 mutex_lock(&tegra->lock); in tegra_xhci_id_work()
1164 if (tegra->host_mode) in tegra_xhci_id_work()
1169 mutex_unlock(&tegra->lock); in tegra_xhci_id_work()
1171 if (tegra->host_mode) { in tegra_xhci_id_work()
1173 if (tegra->otg_usb3_port >= 0) { in tegra_xhci_id_work()
1174 if (tegra->soc->otg_reset_sspi) { in tegra_xhci_id_work()
1177 xhci->shared_hcd, GetPortStatus, in tegra_xhci_id_work()
1178 0, tegra->otg_usb3_port+1, in tegra_xhci_id_work()
1186 msg.data = tegra->otg_usb3_port+1; in tegra_xhci_id_work()
1190 dev_info(tegra->dev, in tegra_xhci_id_work()
1202 if (tegra->otg_usb3_port >= 0) in tegra_xhci_id_work()
1214 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_get_usb2_port()
1215 if (tegra->usbphy[i] && usbphy == tegra->usbphy[i]) in tegra_xusb_get_usb2_port()
1219 return -1; in tegra_xusb_get_usb2_port()
1229 dev_dbg(tegra->dev, "%s(): action is %d", __func__, usbphy->last_event); in tegra_xhci_id_notify()
1231 if ((tegra->host_mode && usbphy->last_event == USB_EVENT_ID) || in tegra_xhci_id_notify()
1232 (!tegra->host_mode && usbphy->last_event != USB_EVENT_ID)) { in tegra_xhci_id_notify()
1233 dev_dbg(tegra->dev, "Same role(%d) received. Ignore", in tegra_xhci_id_notify()
1234 tegra->host_mode); in tegra_xhci_id_notify()
1238 tegra->otg_usb2_port = tegra_xusb_get_usb2_port(tegra, usbphy); in tegra_xhci_id_notify()
1239 tegra->otg_usb3_port = tegra_xusb_padctl_get_usb3_companion( in tegra_xhci_id_notify()
1240 tegra->padctl, in tegra_xhci_id_notify()
1241 tegra->otg_usb2_port); in tegra_xhci_id_notify()
1243 tegra->host_mode = (usbphy->last_event == USB_EVENT_ID) ? true : false; in tegra_xhci_id_notify()
1245 schedule_work(&tegra->id_work); in tegra_xhci_id_notify()
1254 tegra->usbphy = devm_kcalloc(tegra->dev, tegra->num_usb_phys, in tegra_xusb_init_usb_phy()
1255 sizeof(*tegra->usbphy), GFP_KERNEL); in tegra_xusb_init_usb_phy()
1256 if (!tegra->usbphy) in tegra_xusb_init_usb_phy()
1257 return -ENOMEM; in tegra_xusb_init_usb_phy()
1259 INIT_WORK(&tegra->id_work, tegra_xhci_id_work); in tegra_xusb_init_usb_phy()
1260 tegra->id_nb.notifier_call = tegra_xhci_id_notify; in tegra_xusb_init_usb_phy()
1261 tegra->otg_usb2_port = -EINVAL; in tegra_xusb_init_usb_phy()
1262 tegra->otg_usb3_port = -EINVAL; in tegra_xusb_init_usb_phy()
1264 for (i = 0; i < tegra->num_usb_phys; i++) { in tegra_xusb_init_usb_phy()
1270 tegra->usbphy[i] = devm_usb_get_phy_by_node(tegra->dev, in tegra_xusb_init_usb_phy()
1271 phy->dev.of_node, in tegra_xusb_init_usb_phy()
1272 &tegra->id_nb); in tegra_xusb_init_usb_phy()
1273 if (!IS_ERR(tegra->usbphy[i])) { in tegra_xusb_init_usb_phy()
1274 dev_dbg(tegra->dev, "usbphy-%d registered", i); in tegra_xusb_init_usb_phy()
1275 otg_set_host(tegra->usbphy[i]->otg, &tegra->hcd->self); in tegra_xusb_init_usb_phy()
1278 * usb-phy is optional, continue if its not available. in tegra_xusb_init_usb_phy()
1280 tegra->usbphy[i] = NULL; in tegra_xusb_init_usb_phy()
1291 cancel_work_sync(&tegra->id_work); in tegra_xusb_deinit_usb_phy()
1293 for (i = 0; i < tegra->num_usb_phys; i++) in tegra_xusb_deinit_usb_phy()
1294 if (tegra->usbphy[i]) in tegra_xusb_deinit_usb_phy()
1295 otg_set_host(tegra->usbphy[i]->otg, NULL); in tegra_xusb_deinit_usb_phy()
1309 tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL); in tegra_xusb_probe()
1311 return -ENOMEM; in tegra_xusb_probe()
1313 tegra->soc = of_device_get_match_data(&pdev->dev); in tegra_xusb_probe()
1314 mutex_init(&tegra->lock); in tegra_xusb_probe()
1315 tegra->dev = &pdev->dev; in tegra_xusb_probe()
1322 tegra->regs = devm_ioremap_resource(&pdev->dev, regs); in tegra_xusb_probe()
1323 if (IS_ERR(tegra->regs)) in tegra_xusb_probe()
1324 return PTR_ERR(tegra->regs); in tegra_xusb_probe()
1326 tegra->fpci_base = devm_platform_ioremap_resource(pdev, 1); in tegra_xusb_probe()
1327 if (IS_ERR(tegra->fpci_base)) in tegra_xusb_probe()
1328 return PTR_ERR(tegra->fpci_base); in tegra_xusb_probe()
1330 if (tegra->soc->has_ipfs) { in tegra_xusb_probe()
1331 tegra->ipfs_base = devm_platform_ioremap_resource(pdev, 2); in tegra_xusb_probe()
1332 if (IS_ERR(tegra->ipfs_base)) in tegra_xusb_probe()
1333 return PTR_ERR(tegra->ipfs_base); in tegra_xusb_probe()
1336 tegra->xhci_irq = platform_get_irq(pdev, 0); in tegra_xusb_probe()
1337 if (tegra->xhci_irq < 0) in tegra_xusb_probe()
1338 return tegra->xhci_irq; in tegra_xusb_probe()
1340 tegra->mbox_irq = platform_get_irq(pdev, 1); in tegra_xusb_probe()
1341 if (tegra->mbox_irq < 0) in tegra_xusb_probe()
1342 return tegra->mbox_irq; in tegra_xusb_probe()
1344 tegra->padctl = tegra_xusb_padctl_get(&pdev->dev); in tegra_xusb_probe()
1345 if (IS_ERR(tegra->padctl)) in tegra_xusb_probe()
1346 return PTR_ERR(tegra->padctl); in tegra_xusb_probe()
1348 tegra->host_clk = devm_clk_get(&pdev->dev, "xusb_host"); in tegra_xusb_probe()
1349 if (IS_ERR(tegra->host_clk)) { in tegra_xusb_probe()
1350 err = PTR_ERR(tegra->host_clk); in tegra_xusb_probe()
1351 dev_err(&pdev->dev, "failed to get xusb_host: %d\n", err); in tegra_xusb_probe()
1355 tegra->falcon_clk = devm_clk_get(&pdev->dev, "xusb_falcon_src"); in tegra_xusb_probe()
1356 if (IS_ERR(tegra->falcon_clk)) { in tegra_xusb_probe()
1357 err = PTR_ERR(tegra->falcon_clk); in tegra_xusb_probe()
1358 dev_err(&pdev->dev, "failed to get xusb_falcon_src: %d\n", err); in tegra_xusb_probe()
1362 tegra->ss_clk = devm_clk_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1363 if (IS_ERR(tegra->ss_clk)) { in tegra_xusb_probe()
1364 err = PTR_ERR(tegra->ss_clk); in tegra_xusb_probe()
1365 dev_err(&pdev->dev, "failed to get xusb_ss: %d\n", err); in tegra_xusb_probe()
1369 tegra->ss_src_clk = devm_clk_get(&pdev->dev, "xusb_ss_src"); in tegra_xusb_probe()
1370 if (IS_ERR(tegra->ss_src_clk)) { in tegra_xusb_probe()
1371 err = PTR_ERR(tegra->ss_src_clk); in tegra_xusb_probe()
1372 dev_err(&pdev->dev, "failed to get xusb_ss_src: %d\n", err); in tegra_xusb_probe()
1376 tegra->hs_src_clk = devm_clk_get(&pdev->dev, "xusb_hs_src"); in tegra_xusb_probe()
1377 if (IS_ERR(tegra->hs_src_clk)) { in tegra_xusb_probe()
1378 err = PTR_ERR(tegra->hs_src_clk); in tegra_xusb_probe()
1379 dev_err(&pdev->dev, "failed to get xusb_hs_src: %d\n", err); in tegra_xusb_probe()
1383 tegra->fs_src_clk = devm_clk_get(&pdev->dev, "xusb_fs_src"); in tegra_xusb_probe()
1384 if (IS_ERR(tegra->fs_src_clk)) { in tegra_xusb_probe()
1385 err = PTR_ERR(tegra->fs_src_clk); in tegra_xusb_probe()
1386 dev_err(&pdev->dev, "failed to get xusb_fs_src: %d\n", err); in tegra_xusb_probe()
1390 tegra->pll_u_480m = devm_clk_get(&pdev->dev, "pll_u_480m"); in tegra_xusb_probe()
1391 if (IS_ERR(tegra->pll_u_480m)) { in tegra_xusb_probe()
1392 err = PTR_ERR(tegra->pll_u_480m); in tegra_xusb_probe()
1393 dev_err(&pdev->dev, "failed to get pll_u_480m: %d\n", err); in tegra_xusb_probe()
1397 tegra->clk_m = devm_clk_get(&pdev->dev, "clk_m"); in tegra_xusb_probe()
1398 if (IS_ERR(tegra->clk_m)) { in tegra_xusb_probe()
1399 err = PTR_ERR(tegra->clk_m); in tegra_xusb_probe()
1400 dev_err(&pdev->dev, "failed to get clk_m: %d\n", err); in tegra_xusb_probe()
1404 tegra->pll_e = devm_clk_get(&pdev->dev, "pll_e"); in tegra_xusb_probe()
1405 if (IS_ERR(tegra->pll_e)) { in tegra_xusb_probe()
1406 err = PTR_ERR(tegra->pll_e); in tegra_xusb_probe()
1407 dev_err(&pdev->dev, "failed to get pll_e: %d\n", err); in tegra_xusb_probe()
1411 if (!of_property_read_bool(pdev->dev.of_node, "power-domains")) { in tegra_xusb_probe()
1412 tegra->host_rst = devm_reset_control_get(&pdev->dev, in tegra_xusb_probe()
1414 if (IS_ERR(tegra->host_rst)) { in tegra_xusb_probe()
1415 err = PTR_ERR(tegra->host_rst); in tegra_xusb_probe()
1416 dev_err(&pdev->dev, in tegra_xusb_probe()
1421 tegra->ss_rst = devm_reset_control_get(&pdev->dev, "xusb_ss"); in tegra_xusb_probe()
1422 if (IS_ERR(tegra->ss_rst)) { in tegra_xusb_probe()
1423 err = PTR_ERR(tegra->ss_rst); in tegra_xusb_probe()
1424 dev_err(&pdev->dev, "failed to get xusb_ss reset: %d\n", in tegra_xusb_probe()
1430 tegra->ss_clk, in tegra_xusb_probe()
1431 tegra->ss_rst); in tegra_xusb_probe()
1433 dev_err(&pdev->dev, in tegra_xusb_probe()
1439 tegra->host_clk, in tegra_xusb_probe()
1440 tegra->host_rst); in tegra_xusb_probe()
1443 dev_err(&pdev->dev, in tegra_xusb_probe()
1448 err = tegra_xusb_powerdomain_init(&pdev->dev, tegra); in tegra_xusb_probe()
1453 tegra->supplies = devm_kcalloc(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1454 sizeof(*tegra->supplies), GFP_KERNEL); in tegra_xusb_probe()
1455 if (!tegra->supplies) { in tegra_xusb_probe()
1456 err = -ENOMEM; in tegra_xusb_probe()
1460 regulator_bulk_set_supply_names(tegra->supplies, in tegra_xusb_probe()
1461 tegra->soc->supply_names, in tegra_xusb_probe()
1462 tegra->soc->num_supplies); in tegra_xusb_probe()
1464 err = devm_regulator_bulk_get(&pdev->dev, tegra->soc->num_supplies, in tegra_xusb_probe()
1465 tegra->supplies); in tegra_xusb_probe()
1467 dev_err(&pdev->dev, "failed to get regulators: %d\n", err); in tegra_xusb_probe()
1471 for (i = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1472 if (!strncmp(tegra->soc->phy_types[i].name, "usb2", 4)) in tegra_xusb_probe()
1473 tegra->num_usb_phys = tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1474 tegra->num_phys += tegra->soc->phy_types[i].num; in tegra_xusb_probe()
1477 tegra->phys = devm_kcalloc(&pdev->dev, tegra->num_phys, in tegra_xusb_probe()
1478 sizeof(*tegra->phys), GFP_KERNEL); in tegra_xusb_probe()
1479 if (!tegra->phys) { in tegra_xusb_probe()
1480 err = -ENOMEM; in tegra_xusb_probe()
1484 for (i = 0, k = 0; i < tegra->soc->num_types; i++) { in tegra_xusb_probe()
1487 for (j = 0; j < tegra->soc->phy_types[i].num; j++) { in tegra_xusb_probe()
1488 snprintf(prop, sizeof(prop), "%s-%d", in tegra_xusb_probe()
1489 tegra->soc->phy_types[i].name, j); in tegra_xusb_probe()
1491 phy = devm_phy_optional_get(&pdev->dev, prop); in tegra_xusb_probe()
1493 dev_err(&pdev->dev, in tegra_xusb_probe()
1500 tegra->phys[k++] = phy; in tegra_xusb_probe()
1504 tegra->hcd = usb_create_hcd(&tegra_xhci_hc_driver, &pdev->dev, in tegra_xusb_probe()
1505 dev_name(&pdev->dev)); in tegra_xusb_probe()
1506 if (!tegra->hcd) { in tegra_xusb_probe()
1507 err = -ENOMEM; in tegra_xusb_probe()
1511 tegra->hcd->regs = tegra->regs; in tegra_xusb_probe()
1512 tegra->hcd->rsrc_start = regs->start; in tegra_xusb_probe()
1513 tegra->hcd->rsrc_len = resource_size(regs); in tegra_xusb_probe()
1523 dev_err(&pdev->dev, "failed to enable PHYs: %d\n", err); in tegra_xusb_probe()
1531 err = dma_set_mask_and_coherent(tegra->dev, DMA_BIT_MASK(40)); in tegra_xusb_probe()
1533 dev_err(&pdev->dev, "failed to set DMA mask: %d\n", err); in tegra_xusb_probe()
1539 dev_err(&pdev->dev, "failed to request firmware: %d\n", err); in tegra_xusb_probe()
1543 pm_runtime_enable(&pdev->dev); in tegra_xusb_probe()
1545 if (!pm_runtime_enabled(&pdev->dev)) in tegra_xusb_probe()
1546 err = tegra_xusb_runtime_resume(&pdev->dev); in tegra_xusb_probe()
1548 err = pm_runtime_get_sync(&pdev->dev); in tegra_xusb_probe()
1551 dev_err(&pdev->dev, "failed to enable device: %d\n", err); in tegra_xusb_probe()
1559 dev_err(&pdev->dev, "failed to load firmware: %d\n", err); in tegra_xusb_probe()
1563 err = usb_add_hcd(tegra->hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1565 dev_err(&pdev->dev, "failed to add USB HCD: %d\n", err); in tegra_xusb_probe()
1569 device_wakeup_enable(tegra->hcd->self.controller); in tegra_xusb_probe()
1571 xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_probe()
1573 xhci->shared_hcd = usb_create_shared_hcd(&tegra_xhci_hc_driver, in tegra_xusb_probe()
1574 &pdev->dev, in tegra_xusb_probe()
1575 dev_name(&pdev->dev), in tegra_xusb_probe()
1576 tegra->hcd); in tegra_xusb_probe()
1577 if (!xhci->shared_hcd) { in tegra_xusb_probe()
1578 dev_err(&pdev->dev, "failed to create shared HCD\n"); in tegra_xusb_probe()
1579 err = -ENOMEM; in tegra_xusb_probe()
1583 err = usb_add_hcd(xhci->shared_hcd, tegra->xhci_irq, IRQF_SHARED); in tegra_xusb_probe()
1585 dev_err(&pdev->dev, "failed to add shared HCD: %d\n", err); in tegra_xusb_probe()
1591 dev_err(&pdev->dev, "failed to enable messages: %d\n", err); in tegra_xusb_probe()
1595 err = devm_request_threaded_irq(&pdev->dev, tegra->mbox_irq, in tegra_xusb_probe()
1598 dev_name(&pdev->dev), tegra); in tegra_xusb_probe()
1600 dev_err(&pdev->dev, "failed to request IRQ: %d\n", err); in tegra_xusb_probe()
1606 dev_err(&pdev->dev, "failed to init USB PHY: %d\n", err); in tegra_xusb_probe()
1613 usb_remove_hcd(xhci->shared_hcd); in tegra_xusb_probe()
1615 usb_put_hcd(xhci->shared_hcd); in tegra_xusb_probe()
1617 usb_remove_hcd(tegra->hcd); in tegra_xusb_probe()
1619 if (!pm_runtime_status_suspended(&pdev->dev)) in tegra_xusb_probe()
1620 tegra_xusb_runtime_suspend(&pdev->dev); in tegra_xusb_probe()
1622 usb_put_hcd(tegra->hcd); in tegra_xusb_probe()
1624 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_probe()
1625 tegra->fw.phys); in tegra_xusb_probe()
1628 pm_runtime_disable(&pdev->dev); in tegra_xusb_probe()
1630 if (!of_property_read_bool(pdev->dev.of_node, "power-domains")) { in tegra_xusb_probe()
1634 tegra_xusb_powerdomain_remove(&pdev->dev, tegra); in tegra_xusb_probe()
1637 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_probe()
1644 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_remove()
1648 usb_remove_hcd(xhci->shared_hcd); in tegra_xusb_remove()
1649 usb_put_hcd(xhci->shared_hcd); in tegra_xusb_remove()
1650 xhci->shared_hcd = NULL; in tegra_xusb_remove()
1651 usb_remove_hcd(tegra->hcd); in tegra_xusb_remove()
1652 usb_put_hcd(tegra->hcd); in tegra_xusb_remove()
1654 dma_free_coherent(&pdev->dev, tegra->fw.size, tegra->fw.virt, in tegra_xusb_remove()
1655 tegra->fw.phys); in tegra_xusb_remove()
1657 pm_runtime_put_sync(&pdev->dev); in tegra_xusb_remove()
1658 pm_runtime_disable(&pdev->dev); in tegra_xusb_remove()
1660 if (!of_property_read_bool(pdev->dev.of_node, "power-domains")) { in tegra_xusb_remove()
1664 tegra_xusb_powerdomain_remove(&pdev->dev, tegra); in tegra_xusb_remove()
1669 tegra_xusb_padctl_put(tegra->padctl); in tegra_xusb_remove()
1677 struct device *dev = hub->hcd->self.controller; in xhci_hub_ports_suspended()
1682 for (i = 0; i < hub->num_ports; i++) { in xhci_hub_ports_suspended()
1683 value = readl(hub->ports[i]->addr); in xhci_hub_ports_suspended()
1688 dev_info(dev, "%u-%u isn't suspended: %#010x\n", in xhci_hub_ports_suspended()
1689 hub->hcd->self.busnum, i + 1, value); in xhci_hub_ports_suspended()
1699 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_check_ports()
1703 spin_lock_irqsave(&xhci->lock, flags); in tegra_xusb_check_ports()
1705 if (!xhci_hub_ports_suspended(&xhci->usb2_rhub) || in tegra_xusb_check_ports()
1706 !xhci_hub_ports_suspended(&xhci->usb3_rhub)) in tegra_xusb_check_ports()
1707 err = -EBUSY; in tegra_xusb_check_ports()
1709 spin_unlock_irqrestore(&xhci->lock, flags); in tegra_xusb_check_ports()
1716 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_save_context()
1717 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_save_context()
1720 if (soc->ipfs.num_offsets > 0) { in tegra_xusb_save_context()
1721 for (i = 0; i < soc->ipfs.num_offsets; i++) in tegra_xusb_save_context()
1722 ctx->ipfs[i] = ipfs_readl(tegra, soc->ipfs.offsets[i]); in tegra_xusb_save_context()
1725 if (soc->fpci.num_offsets > 0) { in tegra_xusb_save_context()
1726 for (i = 0; i < soc->fpci.num_offsets; i++) in tegra_xusb_save_context()
1727 ctx->fpci[i] = fpci_readl(tegra, soc->fpci.offsets[i]); in tegra_xusb_save_context()
1733 const struct tegra_xusb_context_soc *soc = tegra->soc->context; in tegra_xusb_restore_context()
1734 struct tegra_xusb_context *ctx = &tegra->context; in tegra_xusb_restore_context()
1737 if (soc->fpci.num_offsets > 0) { in tegra_xusb_restore_context()
1738 for (i = 0; i < soc->fpci.num_offsets; i++) in tegra_xusb_restore_context()
1739 fpci_writel(tegra, ctx->fpci[i], soc->fpci.offsets[i]); in tegra_xusb_restore_context()
1742 if (soc->ipfs.num_offsets > 0) { in tegra_xusb_restore_context()
1743 for (i = 0; i < soc->ipfs.num_offsets; i++) in tegra_xusb_restore_context()
1744 ipfs_writel(tegra, ctx->ipfs[i], soc->ipfs.offsets[i]); in tegra_xusb_restore_context()
1750 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_enter_elpg()
1755 dev_err(tegra->dev, "not all ports suspended: %d\n", err); in tegra_xusb_enter_elpg()
1761 dev_err(tegra->dev, "failed to suspend XHCI: %d\n", err); in tegra_xusb_enter_elpg()
1774 struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); in tegra_xusb_exit_elpg()
1779 dev_err(tegra->dev, "failed to enable clocks: %d\n", err); in tegra_xusb_exit_elpg()
1785 dev_err(tegra->dev, "failed to enable PHYs: %d\n", err); in tegra_xusb_exit_elpg()
1794 dev_err(tegra->dev, "failed to load firmware: %d\n", err); in tegra_xusb_exit_elpg()
1800 dev_err(tegra->dev, "failed to enable messages: %d\n", err); in tegra_xusb_exit_elpg()
1806 dev_err(tegra->dev, "failed to resume XHCI: %d\n", err); in tegra_xusb_exit_elpg()
1825 synchronize_irq(tegra->mbox_irq); in tegra_xusb_suspend()
1827 mutex_lock(&tegra->lock); in tegra_xusb_suspend()
1829 mutex_unlock(&tegra->lock); in tegra_xusb_suspend()
1840 mutex_lock(&tegra->lock); in tegra_xusb_resume()
1842 mutex_unlock(&tegra->lock); in tegra_xusb_resume()
1855 "avddio-pex",
1856 "dvddio-pex",
1857 "avdd-usb",
1858 "hvdd-usb-ss",
1862 { .name = "usb3", .num = 2, },
1863 { .name = "usb2", .num = 3, },
1864 { .name = "hsic", .num = 2, },
1910 .ports = {
1928 "dvddio-pex",
1929 "hvddio-pex",
1930 "avdd-usb",
1934 { .name = "usb3", .num = 4, },
1935 { .name = "usb2", .num = 4, },
1936 { .name = "hsic", .num = 1, },
1946 .ports = {
1968 { .name = "usb3", .num = 3, },
1969 { .name = "usb2", .num = 3, },
1970 { .name = "hsic", .num = 1, },
1987 .ports = {
2008 { .name = "usb3", .num = 4, },
2009 { .name = "usb2", .num = 4, },
2019 .ports = {
2037 { .compatible = "nvidia,tegra124-xusb", .data = &tegra124_soc },
2038 { .compatible = "nvidia,tegra210-xusb", .data = &tegra210_soc },
2039 { .compatible = "nvidia,tegra186-xusb", .data = &tegra186_soc },
2040 { .compatible = "nvidia,tegra194-xusb", .data = &tegra194_soc },
2049 .name = "tegra-xusb",
2059 xhci->quirks |= XHCI_PLAT; in tegra_xhci_quirks()
2060 if (tegra && tegra->soc->lpm_support) in tegra_xhci_quirks()
2061 xhci->quirks |= XHCI_LPM_SUPPORT; in tegra_xhci_quirks()
2088 MODULE_DESCRIPTION("NVIDIA Tegra XUSB xHCI host-controller driver");