Lines Matching +full:tegra124 +full:- +full:xusb
1 // SPDX-License-Identifier: GPL-2.0
7 * Copyright (c) 2008-2009, NVIDIA Corporation.
9 * Copyright (c) 2013-2014, NVIDIA Corporation.
12 #define pr_fmt(fmt) "tegra-pcie: " fmt
21 #include <power-domain.h>
33 #include <asm/arch-tegra/xusb-padctl.h>
34 #include <dt-bindings/pinctrl/pinctrl-tegra-xusb.h>
41 * a custom Tegra-specific API. ASAP the older Tegra SoCs' code should be
163 * Fields in PADS_REFCLK_CFG*. Those registers form an array of 16-bit
243 writel(value, pcie->afi.start + offset); in afi_writel()
248 return readl(pcie->afi.start + offset); in afi_readl()
254 writel(value, pcie->pads.start + offset); in pads_writel()
260 return readl(pcie->pads.start + offset); in pads_readl()
267 return readl(port->regs.start + offset); in rp_readl()
273 writel(value, port->regs.start + offset); in rp_writel()
292 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_conf_address()
293 if (port->index + 1 == dev) { in tegra_pcie_conf_address()
294 *address = port->regs.start + (where & ~3); in tegra_pcie_conf_address()
298 return -EFAULT; in tegra_pcie_conf_address()
303 return -EFAULT; in tegra_pcie_conf_address()
306 *address = pcie->cs.start + tegra_pcie_conf_offset(bdf, where); in tegra_pcie_conf_address()
368 addr = ofnode_get_property(node, "assigned-addresses", &len); in tegra_pcie_port_parse_dt()
370 pr_err("property \"assigned-addresses\" not found"); in tegra_pcie_port_parse_dt()
371 return -FDT_ERR_NOTFOUND; in tegra_pcie_port_parse_dt()
374 port->regs.start = fdt32_to_cpu(addr[2]); in tegra_pcie_port_parse_dt()
375 port->regs.end = port->regs.start + fdt32_to_cpu(addr[4]); in tegra_pcie_port_parse_dt()
387 debug("single-mode configuration\n"); in tegra_pcie_get_xbar_config()
392 debug("dual-mode configuration\n"); in tegra_pcie_get_xbar_config()
451 return -FDT_ERR_NOTFOUND; in tegra_pcie_get_xbar_config()
459 err = ofnode_read_u32_default(node, "nvidia,num-lanes", -1); in tegra_pcie_parse_port_info()
461 pr_err("failed to parse \"nvidia,num-lanes\" property"); in tegra_pcie_parse_port_info()
473 *index = PCI_DEV(addr.phys_hi) - 1; in tegra_pcie_parse_port_info()
490 err = dev_read_resource(dev, 0, &pcie->pads); in tegra_pcie_parse_dt()
496 err = dev_read_resource(dev, 1, &pcie->afi); in tegra_pcie_parse_dt()
502 err = dev_read_resource(dev, 2, &pcie->cs); in tegra_pcie_parse_dt()
515 pcie->phy = tegra_xusb_phy_get(TEGRA_XUSB_PADCTL_PCIE); in tegra_pcie_parse_dt()
516 if (pcie->phy) { in tegra_pcie_parse_dt()
517 err = tegra_xusb_phy_prepare(pcie->phy); in tegra_pcie_parse_dt()
545 port->num_lanes = num_lanes; in tegra_pcie_parse_dt()
546 port->index = index; in tegra_pcie_parse_dt()
554 list_add_tail(&port->list, &pcie->ports); in tegra_pcie_parse_dt()
555 port->pcie = pcie; in tegra_pcie_parse_dt()
559 &pcie->xbar); in tegra_pcie_parse_dt()
573 ret = power_domain_on(&pcie->pwrdom); in tegra_pcie_power_on()
579 ret = clk_enable(&pcie->clk_afi); in tegra_pcie_power_on()
585 ret = clk_enable(&pcie->clk_pex); in tegra_pcie_power_on()
591 ret = reset_deassert(&pcie->reset_afi); in tegra_pcie_power_on()
597 ret = reset_deassert(&pcie->reset_pex); in tegra_pcie_power_on()
608 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_power_on()
636 if (soc->has_cml_clk) { in tegra_pcie_power_on()
655 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_pll_wait()
660 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_pll_wait()
665 return -ETIMEDOUT; in tegra_pcie_pll_wait()
670 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_phy_enable()
686 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
688 value |= PADS_PLL_CTL_REFCLK_INTERNAL_CML | soc->tx_ref_sel; in tegra_pcie_phy_enable()
689 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
692 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
694 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
699 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
701 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
726 const struct tegra_pcie_soc *soc = pcie->soc;
734 if (pcie->phy) {
742 if (soc->has_pex_bias_ctrl)
747 value |= AFI_PCIE_CONFIG_PCIE_DISABLE_ALL | pcie->xbar;
749 list_for_each_entry(port, &pcie->ports, list)
750 value &= ~AFI_PCIE_CONFIG_PCIE_DISABLE(port->index);
756 if (soc->has_gen2)
764 if (pcie->phy)
765 err = tegra_xusb_phy_enable(pcie->phy);
777 err = reset_deassert(&pcie->reset_pcie_x);
809 size = resource_size(&pcie->cs);
810 axi = pcie->cs.start;
818 return -EINVAL;
822 size = io->size;
823 axi = io->phys_start;
830 fpci = (((pref->phys_start >> 12) & 0x0fffffff) << 4) | 0x1;
831 size = pref->size;
832 axi = pref->phys_start;
838 /* BAR 3: non-prefetchable memory */
839 fpci = (((mem->phys_start >> 12) & 0x0fffffff) << 4) | 0x1;
840 size = mem->size;
841 axi = mem->phys_start;
875 switch (port->index) {
885 ret = port->pcie->soc->afi_pex2_ctrl;
898 value = afi_readl(port->pcie, ctrl);
900 afi_writel(port->pcie, value, ctrl);
904 value = afi_readl(port->pcie, ctrl);
906 afi_writel(port->pcie, value, ctrl);
911 return port->index;
921 struct tegra_pcie *pcie = port->pcie;
922 const struct tegra_pcie_soc *soc = pcie->soc;
930 if (pcie->soc->has_pex_clkreq_en)
939 if (soc->force_pca_enable) {
946 pads_writel(pcie, soc->pads_refclk_cfg0, PADS_REFCLK_CFG0);
947 if (soc->num_ports > 2)
948 pads_writel(pcie, soc->pads_refclk_cfg1, PADS_REFCLK_CFG1);
970 } while (--timeout);
973 debug("link %u down, retrying\n", port->index);
985 } while (--timeout);
989 } while (--retries);
1000 value = afi_readl(port->pcie, ctrl);
1002 afi_writel(port->pcie, value, ctrl);
1005 value = afi_readl(port->pcie, ctrl);
1007 afi_writel(port->pcie, value, ctrl);
1012 list_del(&port->list);
1020 list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
1021 debug("probing port %u, using %u lanes\n", port->index,
1022 port->num_lanes);
1029 debug("link %u down, ignoring\n", port->index);
1099 pcie->soc = &pci_tegra_soc[id];
1101 INIT_LIST_HEAD(&pcie->ports);
1104 return -EINVAL;
1115 err = clk_get_by_name(dev, "afi", &pcie->clk_afi);
1121 err = clk_get_by_name(dev, "pex", &pcie->clk_pex);
1127 err = reset_get_by_name(dev, "afi", &pcie->reset_afi);
1133 err = reset_get_by_name(dev, "pex", &pcie->reset_pex);
1139 err = reset_get_by_name(dev, "pcie_x", &pcie->reset_pcie_x);
1145 err = power_domain_get(dev, &pcie->pwrdom);
1185 { .compatible = "nvidia,tegra20-pcie", .data = TEGRA20_PCIE },
1186 { .compatible = "nvidia,tegra30-pcie", .data = TEGRA30_PCIE },
1187 { .compatible = "nvidia,tegra124-pcie", .data = TEGRA124_PCIE },
1188 { .compatible = "nvidia,tegra210-pcie", .data = TEGRA210_PCIE },
1189 { .compatible = "nvidia,tegra186-pcie", .data = TEGRA186_PCIE },