Lines Matching full:pcie

3  * PCIe host controller driver for Tegra SoCs
8 * Based on NVIDIA PCIe driver
11 * Bits taken from arch/arm/mach-dove/pcie.c
271 * entries, one entry per PCIe port. These field definitions and desired
376 struct tegra_pcie *pcie; member
394 static inline void afi_writel(struct tegra_pcie *pcie, u32 value, in afi_writel() argument
397 writel(value, pcie->afi + offset); in afi_writel()
400 static inline u32 afi_readl(struct tegra_pcie *pcie, unsigned long offset) in afi_readl() argument
402 return readl(pcie->afi + offset); in afi_readl()
405 static inline void pads_writel(struct tegra_pcie *pcie, u32 value, in pads_writel() argument
408 writel(value, pcie->pads + offset); in pads_writel()
411 static inline u32 pads_readl(struct tegra_pcie *pcie, unsigned long offset) in pads_readl() argument
413 return readl(pcie->pads + offset); in pads_readl()
418 * defined by PCIe. However it deviates a bit in how the 4 bits for extended
448 struct tegra_pcie *pcie = bus->sysdata; in tegra_pcie_map_bus() local
455 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_map_bus()
469 afi_writel(pcie, base, AFI_FPCI_BAR0); in tegra_pcie_map_bus()
472 addr = pcie->cfg + (offset & (SZ_4K - 1)); in tegra_pcie_map_bus()
506 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_port_get_pex_ctrl()
535 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_reset()
537 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_reset()
545 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_reset()
547 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_reset()
553 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_enable_rp_features()
591 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_program_ectl_settings()
639 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_apply_sw_fixup()
662 * PCIe link doesn't come up with few legacy PCIe endpoints if in tegra_pcie_apply_sw_fixup()
676 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_port_enable()
680 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_enable()
688 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_enable()
709 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_port_disable()
713 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_disable()
715 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_disable()
718 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_disable()
724 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_disable()
726 /* disable PCIe port and set CLKREQ# as GPIO to allow PLLE power down */ in tegra_pcie_port_disable()
727 value = afi_readl(port->pcie, AFI_PCIE_CONFIG); in tegra_pcie_port_disable()
730 afi_writel(port->pcie, value, AFI_PCIE_CONFIG); in tegra_pcie_port_disable()
735 struct tegra_pcie *pcie = port->pcie; in tegra_pcie_port_free() local
736 struct device *dev = pcie->dev; in tegra_pcie_port_free()
745 /* Tegra PCIE root complex wrongly reports device class */
755 /* Tegra20 and Tegra30 PCIE requires relaxed ordering */
767 struct tegra_pcie *pcie = pdev->bus->sysdata; in tegra_pcie_map_irq() local
774 irq = pcie->irq; in tegra_pcie_map_irq()
798 struct tegra_pcie *pcie = arg; in tegra_pcie_isr() local
799 struct device *dev = pcie->dev; in tegra_pcie_isr()
802 code = afi_readl(pcie, AFI_INTR_CODE) & AFI_INTR_CODE_MASK; in tegra_pcie_isr()
803 signature = afi_readl(pcie, AFI_INTR_SIGNATURE); in tegra_pcie_isr()
804 afi_writel(pcie, 0, AFI_INTR_CODE); in tegra_pcie_isr()
823 u32 fpci = afi_readl(pcie, AFI_UPPER_FPCI_ADDRESS) & 0xff; in tegra_pcie_isr()
843 static void tegra_pcie_setup_translations(struct tegra_pcie *pcie) in tegra_pcie_setup_translations() argument
847 struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); in tegra_pcie_setup_translations()
850 size = resource_size(&pcie->cs); in tegra_pcie_setup_translations()
851 afi_writel(pcie, pcie->cs.start, AFI_AXI_BAR0_START); in tegra_pcie_setup_translations()
852 afi_writel(pcie, size >> 12, AFI_AXI_BAR0_SZ); in tegra_pcie_setup_translations()
865 afi_writel(pcie, axi_address, AFI_AXI_BAR1_START); in tegra_pcie_setup_translations()
866 afi_writel(pcie, size >> 12, AFI_AXI_BAR1_SZ); in tegra_pcie_setup_translations()
867 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR1); in tegra_pcie_setup_translations()
875 afi_writel(pcie, axi_address, AFI_AXI_BAR2_START); in tegra_pcie_setup_translations()
876 afi_writel(pcie, size >> 12, AFI_AXI_BAR2_SZ); in tegra_pcie_setup_translations()
877 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR2); in tegra_pcie_setup_translations()
881 afi_writel(pcie, axi_address, AFI_AXI_BAR3_START); in tegra_pcie_setup_translations()
882 afi_writel(pcie, size >> 12, AFI_AXI_BAR3_SZ); in tegra_pcie_setup_translations()
883 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR3); in tegra_pcie_setup_translations()
890 afi_writel(pcie, 0, AFI_AXI_BAR4_START); in tegra_pcie_setup_translations()
891 afi_writel(pcie, 0, AFI_AXI_BAR4_SZ); in tegra_pcie_setup_translations()
892 afi_writel(pcie, 0, AFI_FPCI_BAR4); in tegra_pcie_setup_translations()
894 afi_writel(pcie, 0, AFI_AXI_BAR5_START); in tegra_pcie_setup_translations()
895 afi_writel(pcie, 0, AFI_AXI_BAR5_SZ); in tegra_pcie_setup_translations()
896 afi_writel(pcie, 0, AFI_FPCI_BAR5); in tegra_pcie_setup_translations()
898 if (pcie->soc->has_cache_bars) { in tegra_pcie_setup_translations()
900 afi_writel(pcie, 0, AFI_CACHE_BAR0_ST); in tegra_pcie_setup_translations()
901 afi_writel(pcie, 0, AFI_CACHE_BAR0_SZ); in tegra_pcie_setup_translations()
902 afi_writel(pcie, 0, AFI_CACHE_BAR1_ST); in tegra_pcie_setup_translations()
903 afi_writel(pcie, 0, AFI_CACHE_BAR1_SZ); in tegra_pcie_setup_translations()
907 afi_writel(pcie, 0, AFI_MSI_FPCI_BAR_ST); in tegra_pcie_setup_translations()
908 afi_writel(pcie, 0, AFI_MSI_BAR_SZ); in tegra_pcie_setup_translations()
909 afi_writel(pcie, 0, AFI_MSI_AXI_BAR_ST); in tegra_pcie_setup_translations()
910 afi_writel(pcie, 0, AFI_MSI_BAR_SZ); in tegra_pcie_setup_translations()
913 static int tegra_pcie_pll_wait(struct tegra_pcie *pcie, unsigned long timeout) in tegra_pcie_pll_wait() argument
915 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_pll_wait()
921 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_pll_wait()
929 static int tegra_pcie_phy_enable(struct tegra_pcie *pcie) in tegra_pcie_phy_enable() argument
931 struct device *dev = pcie->dev; in tegra_pcie_phy_enable()
932 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_phy_enable()
936 /* initialize internal PHY, enable up to 16 PCIE lanes */ in tegra_pcie_phy_enable()
937 pads_writel(pcie, 0x0, PADS_CTL_SEL); in tegra_pcie_phy_enable()
940 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
942 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
948 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
951 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
954 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
956 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
961 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
963 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
966 err = tegra_pcie_pll_wait(pcie, 500); in tegra_pcie_phy_enable()
973 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
975 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
978 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
980 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
985 static int tegra_pcie_phy_disable(struct tegra_pcie *pcie) in tegra_pcie_phy_disable() argument
987 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_phy_disable()
991 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_disable()
993 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_disable()
996 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_disable()
998 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_disable()
1001 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_disable()
1003 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_disable()
1012 struct device *dev = port->pcie->dev; in tegra_pcie_port_phy_power_on()
1029 struct device *dev = port->pcie->dev; in tegra_pcie_port_phy_power_off()
1045 static int tegra_pcie_phy_power_on(struct tegra_pcie *pcie) in tegra_pcie_phy_power_on() argument
1047 struct device *dev = pcie->dev; in tegra_pcie_phy_power_on()
1051 if (pcie->legacy_phy) { in tegra_pcie_phy_power_on()
1052 if (pcie->phy) in tegra_pcie_phy_power_on()
1053 err = phy_power_on(pcie->phy); in tegra_pcie_phy_power_on()
1055 err = tegra_pcie_phy_enable(pcie); in tegra_pcie_phy_power_on()
1063 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_phy_power_on()
1067 "failed to power on PCIe port %u PHY: %d\n", in tegra_pcie_phy_power_on()
1076 static int tegra_pcie_phy_power_off(struct tegra_pcie *pcie) in tegra_pcie_phy_power_off() argument
1078 struct device *dev = pcie->dev; in tegra_pcie_phy_power_off()
1082 if (pcie->legacy_phy) { in tegra_pcie_phy_power_off()
1083 if (pcie->phy) in tegra_pcie_phy_power_off()
1084 err = phy_power_off(pcie->phy); in tegra_pcie_phy_power_off()
1086 err = tegra_pcie_phy_disable(pcie); in tegra_pcie_phy_power_off()
1094 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_phy_power_off()
1098 "failed to power off PCIe port %u PHY: %d\n", in tegra_pcie_phy_power_off()
1107 static void tegra_pcie_enable_controller(struct tegra_pcie *pcie) in tegra_pcie_enable_controller() argument
1109 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_enable_controller()
1114 if (pcie->phy) { in tegra_pcie_enable_controller()
1115 value = afi_readl(pcie, AFI_PLLE_CONTROL); in tegra_pcie_enable_controller()
1118 afi_writel(pcie, value, AFI_PLLE_CONTROL); in tegra_pcie_enable_controller()
1121 /* power down PCIe slot clock bias pad */ in tegra_pcie_enable_controller()
1123 afi_writel(pcie, 0, AFI_PEXBIAS_CTRL_0); in tegra_pcie_enable_controller()
1126 value = afi_readl(pcie, AFI_PCIE_CONFIG); in tegra_pcie_enable_controller()
1128 value |= AFI_PCIE_CONFIG_PCIE_DISABLE_ALL | pcie->xbar_config; in tegra_pcie_enable_controller()
1131 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_enable_controller()
1136 afi_writel(pcie, value, AFI_PCIE_CONFIG); in tegra_pcie_enable_controller()
1139 value = afi_readl(pcie, AFI_FUSE); in tegra_pcie_enable_controller()
1141 afi_writel(pcie, value, AFI_FUSE); in tegra_pcie_enable_controller()
1143 value = afi_readl(pcie, AFI_FUSE); in tegra_pcie_enable_controller()
1145 afi_writel(pcie, value, AFI_FUSE); in tegra_pcie_enable_controller()
1148 /* Disable AFI dynamic clock gating and enable PCIe */ in tegra_pcie_enable_controller()
1149 value = afi_readl(pcie, AFI_CONFIGURATION); in tegra_pcie_enable_controller()
1152 afi_writel(pcie, value, AFI_CONFIGURATION); in tegra_pcie_enable_controller()
1161 afi_writel(pcie, value, AFI_AFI_INTR_ENABLE); in tegra_pcie_enable_controller()
1162 afi_writel(pcie, 0xffffffff, AFI_SM_INTR_ENABLE); in tegra_pcie_enable_controller()
1165 afi_writel(pcie, AFI_INTR_MASK_INT_MASK, AFI_INTR_MASK); in tegra_pcie_enable_controller()
1168 afi_writel(pcie, 0, AFI_FPCI_ERROR_MASKS); in tegra_pcie_enable_controller()
1171 static void tegra_pcie_power_off(struct tegra_pcie *pcie) in tegra_pcie_power_off() argument
1173 struct device *dev = pcie->dev; in tegra_pcie_power_off()
1174 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_power_off()
1177 reset_control_assert(pcie->afi_rst); in tegra_pcie_power_off()
1179 clk_disable_unprepare(pcie->pll_e); in tegra_pcie_power_off()
1181 clk_disable_unprepare(pcie->cml_clk); in tegra_pcie_power_off()
1182 clk_disable_unprepare(pcie->afi_clk); in tegra_pcie_power_off()
1187 err = regulator_bulk_disable(pcie->num_supplies, pcie->supplies); in tegra_pcie_power_off()
1192 static int tegra_pcie_power_on(struct tegra_pcie *pcie) in tegra_pcie_power_on() argument
1194 struct device *dev = pcie->dev; in tegra_pcie_power_on()
1195 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_power_on()
1198 reset_control_assert(pcie->pcie_xrst); in tegra_pcie_power_on()
1199 reset_control_assert(pcie->afi_rst); in tegra_pcie_power_on()
1200 reset_control_assert(pcie->pex_rst); in tegra_pcie_power_on()
1206 err = regulator_bulk_enable(pcie->num_supplies, pcie->supplies); in tegra_pcie_power_on()
1223 err = clk_prepare_enable(pcie->afi_clk); in tegra_pcie_power_on()
1230 err = clk_prepare_enable(pcie->cml_clk); in tegra_pcie_power_on()
1237 err = clk_prepare_enable(pcie->pll_e); in tegra_pcie_power_on()
1243 reset_control_deassert(pcie->afi_rst); in tegra_pcie_power_on()
1249 clk_disable_unprepare(pcie->cml_clk); in tegra_pcie_power_on()
1251 clk_disable_unprepare(pcie->afi_clk); in tegra_pcie_power_on()
1256 regulator_bulk_disable(pcie->num_supplies, pcie->supplies); in tegra_pcie_power_on()
1261 static void tegra_pcie_apply_pad_settings(struct tegra_pcie *pcie) in tegra_pcie_apply_pad_settings() argument
1263 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_apply_pad_settings()
1266 pads_writel(pcie, soc->pads_refclk_cfg0, PADS_REFCLK_CFG0); in tegra_pcie_apply_pad_settings()
1269 pads_writel(pcie, soc->pads_refclk_cfg1, PADS_REFCLK_CFG1); in tegra_pcie_apply_pad_settings()
1272 static int tegra_pcie_clocks_get(struct tegra_pcie *pcie) in tegra_pcie_clocks_get() argument
1274 struct device *dev = pcie->dev; in tegra_pcie_clocks_get()
1275 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_clocks_get()
1277 pcie->pex_clk = devm_clk_get(dev, "pex"); in tegra_pcie_clocks_get()
1278 if (IS_ERR(pcie->pex_clk)) in tegra_pcie_clocks_get()
1279 return PTR_ERR(pcie->pex_clk); in tegra_pcie_clocks_get()
1281 pcie->afi_clk = devm_clk_get(dev, "afi"); in tegra_pcie_clocks_get()
1282 if (IS_ERR(pcie->afi_clk)) in tegra_pcie_clocks_get()
1283 return PTR_ERR(pcie->afi_clk); in tegra_pcie_clocks_get()
1285 pcie->pll_e = devm_clk_get(dev, "pll_e"); in tegra_pcie_clocks_get()
1286 if (IS_ERR(pcie->pll_e)) in tegra_pcie_clocks_get()
1287 return PTR_ERR(pcie->pll_e); in tegra_pcie_clocks_get()
1290 pcie->cml_clk = devm_clk_get(dev, "cml"); in tegra_pcie_clocks_get()
1291 if (IS_ERR(pcie->cml_clk)) in tegra_pcie_clocks_get()
1292 return PTR_ERR(pcie->cml_clk); in tegra_pcie_clocks_get()
1298 static int tegra_pcie_resets_get(struct tegra_pcie *pcie) in tegra_pcie_resets_get() argument
1300 struct device *dev = pcie->dev; in tegra_pcie_resets_get()
1302 pcie->pex_rst = devm_reset_control_get_exclusive(dev, "pex"); in tegra_pcie_resets_get()
1303 if (IS_ERR(pcie->pex_rst)) in tegra_pcie_resets_get()
1304 return PTR_ERR(pcie->pex_rst); in tegra_pcie_resets_get()
1306 pcie->afi_rst = devm_reset_control_get_exclusive(dev, "afi"); in tegra_pcie_resets_get()
1307 if (IS_ERR(pcie->afi_rst)) in tegra_pcie_resets_get()
1308 return PTR_ERR(pcie->afi_rst); in tegra_pcie_resets_get()
1310 pcie->pcie_xrst = devm_reset_control_get_exclusive(dev, "pcie_x"); in tegra_pcie_resets_get()
1311 if (IS_ERR(pcie->pcie_xrst)) in tegra_pcie_resets_get()
1312 return PTR_ERR(pcie->pcie_xrst); in tegra_pcie_resets_get()
1317 static int tegra_pcie_phys_get_legacy(struct tegra_pcie *pcie) in tegra_pcie_phys_get_legacy() argument
1319 struct device *dev = pcie->dev; in tegra_pcie_phys_get_legacy()
1322 pcie->phy = devm_phy_optional_get(dev, "pcie"); in tegra_pcie_phys_get_legacy()
1323 if (IS_ERR(pcie->phy)) { in tegra_pcie_phys_get_legacy()
1324 err = PTR_ERR(pcie->phy); in tegra_pcie_phys_get_legacy()
1329 err = phy_init(pcie->phy); in tegra_pcie_phys_get_legacy()
1335 pcie->legacy_phy = true; in tegra_pcie_phys_get_legacy()
1363 struct device *dev = port->pcie->dev; in tegra_pcie_port_get_phys()
1373 phy = devm_of_phy_optional_get_index(dev, port->np, "pcie", i); in tegra_pcie_port_get_phys()
1393 static int tegra_pcie_phys_get(struct tegra_pcie *pcie) in tegra_pcie_phys_get() argument
1395 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_phys_get()
1396 struct device_node *np = pcie->dev->of_node; in tegra_pcie_phys_get()
1401 return tegra_pcie_phys_get_legacy(pcie); in tegra_pcie_phys_get()
1403 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_phys_get()
1412 static void tegra_pcie_phys_put(struct tegra_pcie *pcie) in tegra_pcie_phys_put() argument
1415 struct device *dev = pcie->dev; in tegra_pcie_phys_put()
1418 if (pcie->legacy_phy) { in tegra_pcie_phys_put()
1419 err = phy_exit(pcie->phy); in tegra_pcie_phys_put()
1425 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_phys_put()
1436 static int tegra_pcie_get_resources(struct tegra_pcie *pcie) in tegra_pcie_get_resources() argument
1438 struct device *dev = pcie->dev; in tegra_pcie_get_resources()
1441 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_get_resources()
1444 err = tegra_pcie_clocks_get(pcie); in tegra_pcie_get_resources()
1450 err = tegra_pcie_resets_get(pcie); in tegra_pcie_get_resources()
1457 err = tegra_pcie_phys_get(pcie); in tegra_pcie_get_resources()
1464 pcie->pads = devm_platform_ioremap_resource_byname(pdev, "pads"); in tegra_pcie_get_resources()
1465 if (IS_ERR(pcie->pads)) { in tegra_pcie_get_resources()
1466 err = PTR_ERR(pcie->pads); in tegra_pcie_get_resources()
1470 pcie->afi = devm_platform_ioremap_resource_byname(pdev, "afi"); in tegra_pcie_get_resources()
1471 if (IS_ERR(pcie->afi)) { in tegra_pcie_get_resources()
1472 err = PTR_ERR(pcie->afi); in tegra_pcie_get_resources()
1483 pcie->cs = *res; in tegra_pcie_get_resources()
1486 pcie->cs.end = pcie->cs.start + SZ_4K - 1; in tegra_pcie_get_resources()
1488 pcie->cfg = devm_ioremap_resource(dev, &pcie->cs); in tegra_pcie_get_resources()
1489 if (IS_ERR(pcie->cfg)) { in tegra_pcie_get_resources()
1490 err = PTR_ERR(pcie->cfg); in tegra_pcie_get_resources()
1499 pcie->irq = err; in tegra_pcie_get_resources()
1501 err = request_irq(pcie->irq, tegra_pcie_isr, IRQF_SHARED, "PCIE", pcie); in tegra_pcie_get_resources()
1511 tegra_pcie_phys_put(pcie); in tegra_pcie_get_resources()
1515 static int tegra_pcie_put_resources(struct tegra_pcie *pcie) in tegra_pcie_put_resources() argument
1517 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_put_resources()
1519 if (pcie->irq > 0) in tegra_pcie_put_resources()
1520 free_irq(pcie->irq, pcie); in tegra_pcie_put_resources()
1523 tegra_pcie_phys_put(pcie); in tegra_pcie_put_resources()
1530 struct tegra_pcie *pcie = port->pcie; in tegra_pcie_pme_turnoff() local
1531 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_pme_turnoff()
1536 val = afi_readl(pcie, AFI_PCIE_PME); in tegra_pcie_pme_turnoff()
1538 afi_writel(pcie, val, AFI_PCIE_PME); in tegra_pcie_pme_turnoff()
1541 err = readl_poll_timeout(pcie->afi + AFI_PCIE_PME, val, in tegra_pcie_pme_turnoff()
1544 dev_err(pcie->dev, "PME Ack is not received on port: %d\n", in tegra_pcie_pme_turnoff()
1549 val = afi_readl(pcie, AFI_PCIE_PME); in tegra_pcie_pme_turnoff()
1551 afi_writel(pcie, val, AFI_PCIE_PME); in tegra_pcie_pme_turnoff()
1587 struct tegra_pcie *pcie = data; in tegra_pcie_msi_irq() local
1588 struct device *dev = pcie->dev; in tegra_pcie_msi_irq()
1589 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_msi_irq()
1593 unsigned long reg = afi_readl(pcie, AFI_MSI_VEC0 + i * 4); in tegra_pcie_msi_irq()
1601 afi_writel(pcie, 1 << offset, AFI_MSI_VEC0 + i * 4); in tegra_pcie_msi_irq()
1618 reg = afi_readl(pcie, AFI_MSI_VEC0 + i * 4); in tegra_pcie_msi_irq()
1668 .name = "Tegra PCIe MSI",
1690 static int tegra_pcie_msi_setup(struct tegra_pcie *pcie) in tegra_pcie_msi_setup() argument
1692 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); in tegra_pcie_msi_setup()
1693 struct platform_device *pdev = to_platform_device(pcie->dev); in tegra_pcie_msi_setup()
1694 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_msi_setup()
1695 struct device *dev = pcie->dev; in tegra_pcie_msi_setup()
1718 tegra_msi_irq_chip.name, pcie); in tegra_pcie_msi_setup()
1724 /* Though the PCIe controller can address >32-bit address space, to in tegra_pcie_msi_setup()
1748 free_irq(msi->irq, pcie); in tegra_pcie_msi_setup()
1754 static void tegra_pcie_enable_msi(struct tegra_pcie *pcie) in tegra_pcie_enable_msi() argument
1756 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_enable_msi()
1757 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_enable_msi()
1760 afi_writel(pcie, msi->phys >> soc->msi_base_shift, AFI_MSI_FPCI_BAR_ST); in tegra_pcie_enable_msi()
1761 afi_writel(pcie, msi->phys, AFI_MSI_AXI_BAR_ST); in tegra_pcie_enable_msi()
1763 afi_writel(pcie, 1, AFI_MSI_BAR_SZ); in tegra_pcie_enable_msi()
1766 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC0); in tegra_pcie_enable_msi()
1767 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC1); in tegra_pcie_enable_msi()
1768 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC2); in tegra_pcie_enable_msi()
1769 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC3); in tegra_pcie_enable_msi()
1770 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC4); in tegra_pcie_enable_msi()
1771 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC5); in tegra_pcie_enable_msi()
1772 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC6); in tegra_pcie_enable_msi()
1773 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC7); in tegra_pcie_enable_msi()
1776 reg = afi_readl(pcie, AFI_INTR_MASK); in tegra_pcie_enable_msi()
1778 afi_writel(pcie, reg, AFI_INTR_MASK); in tegra_pcie_enable_msi()
1781 static void tegra_pcie_msi_teardown(struct tegra_pcie *pcie) in tegra_pcie_msi_teardown() argument
1783 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_msi_teardown()
1786 dma_free_attrs(pcie->dev, PAGE_SIZE, msi->virt, msi->phys, in tegra_pcie_msi_teardown()
1790 free_irq(msi->irq, pcie); in tegra_pcie_msi_teardown()
1801 static int tegra_pcie_disable_msi(struct tegra_pcie *pcie) in tegra_pcie_disable_msi() argument
1806 value = afi_readl(pcie, AFI_INTR_MASK); in tegra_pcie_disable_msi()
1808 afi_writel(pcie, value, AFI_INTR_MASK); in tegra_pcie_disable_msi()
1811 afi_writel(pcie, 0, AFI_MSI_EN_VEC0); in tegra_pcie_disable_msi()
1812 afi_writel(pcie, 0, AFI_MSI_EN_VEC1); in tegra_pcie_disable_msi()
1813 afi_writel(pcie, 0, AFI_MSI_EN_VEC2); in tegra_pcie_disable_msi()
1814 afi_writel(pcie, 0, AFI_MSI_EN_VEC3); in tegra_pcie_disable_msi()
1815 afi_writel(pcie, 0, AFI_MSI_EN_VEC4); in tegra_pcie_disable_msi()
1816 afi_writel(pcie, 0, AFI_MSI_EN_VEC5); in tegra_pcie_disable_msi()
1817 afi_writel(pcie, 0, AFI_MSI_EN_VEC6); in tegra_pcie_disable_msi()
1818 afi_writel(pcie, 0, AFI_MSI_EN_VEC7); in tegra_pcie_disable_msi()
1823 static void tegra_pcie_disable_interrupts(struct tegra_pcie *pcie) in tegra_pcie_disable_interrupts() argument
1827 value = afi_readl(pcie, AFI_INTR_MASK); in tegra_pcie_disable_interrupts()
1829 afi_writel(pcie, value, AFI_INTR_MASK); in tegra_pcie_disable_interrupts()
1832 static int tegra_pcie_get_xbar_config(struct tegra_pcie *pcie, u32 lanes, in tegra_pcie_get_xbar_config() argument
1835 struct device *dev = pcie->dev; in tegra_pcie_get_xbar_config()
1838 if (of_device_is_compatible(np, "nvidia,tegra186-pcie")) { in tegra_pcie_get_xbar_config()
1862 } else if (of_device_is_compatible(np, "nvidia,tegra124-pcie") || in tegra_pcie_get_xbar_config()
1863 of_device_is_compatible(np, "nvidia,tegra210-pcie")) { in tegra_pcie_get_xbar_config()
1875 } else if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) { in tegra_pcie_get_xbar_config()
1892 } else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) { in tegra_pcie_get_xbar_config()
1938 static int tegra_pcie_get_legacy_regulators(struct tegra_pcie *pcie) in tegra_pcie_get_legacy_regulators() argument
1940 struct device *dev = pcie->dev; in tegra_pcie_get_legacy_regulators()
1943 if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) in tegra_pcie_get_legacy_regulators()
1944 pcie->num_supplies = 3; in tegra_pcie_get_legacy_regulators()
1945 else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) in tegra_pcie_get_legacy_regulators()
1946 pcie->num_supplies = 2; in tegra_pcie_get_legacy_regulators()
1948 if (pcie->num_supplies == 0) { in tegra_pcie_get_legacy_regulators()
1953 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, in tegra_pcie_get_legacy_regulators()
1954 sizeof(*pcie->supplies), in tegra_pcie_get_legacy_regulators()
1956 if (!pcie->supplies) in tegra_pcie_get_legacy_regulators()
1959 pcie->supplies[0].supply = "pex-clk"; in tegra_pcie_get_legacy_regulators()
1960 pcie->supplies[1].supply = "vdd"; in tegra_pcie_get_legacy_regulators()
1962 if (pcie->num_supplies > 2) in tegra_pcie_get_legacy_regulators()
1963 pcie->supplies[2].supply = "avdd"; in tegra_pcie_get_legacy_regulators()
1965 return devm_regulator_bulk_get(dev, pcie->num_supplies, pcie->supplies); in tegra_pcie_get_legacy_regulators()
1977 static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) in tegra_pcie_get_regulators() argument
1979 struct device *dev = pcie->dev; in tegra_pcie_get_regulators()
1983 if (of_device_is_compatible(np, "nvidia,tegra186-pcie")) { in tegra_pcie_get_regulators()
1984 pcie->num_supplies = 4; in tegra_pcie_get_regulators()
1986 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, in tegra_pcie_get_regulators()
1987 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
1989 if (!pcie->supplies) in tegra_pcie_get_regulators()
1992 pcie->supplies[i++].supply = "dvdd-pex"; in tegra_pcie_get_regulators()
1993 pcie->supplies[i++].supply = "hvdd-pex-pll"; in tegra_pcie_get_regulators()
1994 pcie->supplies[i++].supply = "hvdd-pex"; in tegra_pcie_get_regulators()
1995 pcie->supplies[i++].supply = "vddio-pexctl-aud"; in tegra_pcie_get_regulators()
1996 } else if (of_device_is_compatible(np, "nvidia,tegra210-pcie")) { in tegra_pcie_get_regulators()
1997 pcie->num_supplies = 3; in tegra_pcie_get_regulators()
1999 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2000 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2002 if (!pcie->supplies) in tegra_pcie_get_regulators()
2005 pcie->supplies[i++].supply = "hvddio-pex"; in tegra_pcie_get_regulators()
2006 pcie->supplies[i++].supply = "dvddio-pex"; in tegra_pcie_get_regulators()
2007 pcie->supplies[i++].supply = "vddio-pex-ctl"; in tegra_pcie_get_regulators()
2008 } else if (of_device_is_compatible(np, "nvidia,tegra124-pcie")) { in tegra_pcie_get_regulators()
2009 pcie->num_supplies = 4; in tegra_pcie_get_regulators()
2011 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2012 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2014 if (!pcie->supplies) in tegra_pcie_get_regulators()
2017 pcie->supplies[i++].supply = "avddio-pex"; in tegra_pcie_get_regulators()
2018 pcie->supplies[i++].supply = "dvddio-pex"; in tegra_pcie_get_regulators()
2019 pcie->supplies[i++].supply = "hvdd-pex"; in tegra_pcie_get_regulators()
2020 pcie->supplies[i++].supply = "vddio-pex-ctl"; in tegra_pcie_get_regulators()
2021 } else if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) { in tegra_pcie_get_regulators()
2032 pcie->num_supplies = 4 + (need_pexa ? 2 : 0) + in tegra_pcie_get_regulators()
2035 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2036 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2038 if (!pcie->supplies) in tegra_pcie_get_regulators()
2041 pcie->supplies[i++].supply = "avdd-pex-pll"; in tegra_pcie_get_regulators()
2042 pcie->supplies[i++].supply = "hvdd-pex"; in tegra_pcie_get_regulators()
2043 pcie->supplies[i++].supply = "vddio-pex-ctl"; in tegra_pcie_get_regulators()
2044 pcie->supplies[i++].supply = "avdd-plle"; in tegra_pcie_get_regulators()
2047 pcie->supplies[i++].supply = "avdd-pexa"; in tegra_pcie_get_regulators()
2048 pcie->supplies[i++].supply = "vdd-pexa"; in tegra_pcie_get_regulators()
2052 pcie->supplies[i++].supply = "avdd-pexb"; in tegra_pcie_get_regulators()
2053 pcie->supplies[i++].supply = "vdd-pexb"; in tegra_pcie_get_regulators()
2055 } else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) { in tegra_pcie_get_regulators()
2056 pcie->num_supplies = 5; in tegra_pcie_get_regulators()
2058 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2059 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2061 if (!pcie->supplies) in tegra_pcie_get_regulators()
2064 pcie->supplies[0].supply = "avdd-pex"; in tegra_pcie_get_regulators()
2065 pcie->supplies[1].supply = "vdd-pex"; in tegra_pcie_get_regulators()
2066 pcie->supplies[2].supply = "avdd-pex-pll"; in tegra_pcie_get_regulators()
2067 pcie->supplies[3].supply = "avdd-plle"; in tegra_pcie_get_regulators()
2068 pcie->supplies[4].supply = "vddio-pex-clk"; in tegra_pcie_get_regulators()
2071 if (of_regulator_bulk_available(dev->of_node, pcie->supplies, in tegra_pcie_get_regulators()
2072 pcie->num_supplies)) in tegra_pcie_get_regulators()
2073 return devm_regulator_bulk_get(dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2074 pcie->supplies); in tegra_pcie_get_regulators()
2083 devm_kfree(dev, pcie->supplies); in tegra_pcie_get_regulators()
2084 pcie->num_supplies = 0; in tegra_pcie_get_regulators()
2086 return tegra_pcie_get_legacy_regulators(pcie); in tegra_pcie_get_regulators()
2089 static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) in tegra_pcie_parse_dt() argument
2091 struct device *dev = pcie->dev; in tegra_pcie_parse_dt()
2093 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_parse_dt()
2159 rp->pcie = pcie; in tegra_pcie_parse_dt()
2191 list_add_tail(&rp->list, &pcie->ports); in tegra_pcie_parse_dt()
2194 err = tegra_pcie_get_xbar_config(pcie, lanes, &pcie->xbar_config); in tegra_pcie_parse_dt()
2200 err = tegra_pcie_get_regulators(pcie, mask); in tegra_pcie_parse_dt()
2212 * FIXME: If there are no PCIe cards attached, then calling this function
2219 struct device *dev = port->pcie->dev; in tegra_pcie_port_check_link()
2264 static void tegra_pcie_change_link_speed(struct tegra_pcie *pcie) in tegra_pcie_change_link_speed() argument
2266 struct device *dev = pcie->dev; in tegra_pcie_change_link_speed()
2271 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_change_link_speed()
2298 dev_warn(dev, "PCIe port %u link is in recovery\n", in tegra_pcie_change_link_speed()
2322 static void tegra_pcie_enable_ports(struct tegra_pcie *pcie) in tegra_pcie_enable_ports() argument
2324 struct device *dev = pcie->dev; in tegra_pcie_enable_ports()
2327 list_for_each_entry_safe(port, tmp, &pcie->ports, list) { in tegra_pcie_enable_ports()
2335 reset_control_deassert(pcie->pcie_xrst); in tegra_pcie_enable_ports()
2337 list_for_each_entry_safe(port, tmp, &pcie->ports, list) { in tegra_pcie_enable_ports()
2347 if (pcie->soc->has_gen2) in tegra_pcie_enable_ports()
2348 tegra_pcie_change_link_speed(pcie); in tegra_pcie_enable_ports()
2351 static void tegra_pcie_disable_ports(struct tegra_pcie *pcie) in tegra_pcie_disable_ports() argument
2355 reset_control_assert(pcie->pcie_xrst); in tegra_pcie_disable_ports()
2357 list_for_each_entry_safe(port, tmp, &pcie->ports, list) in tegra_pcie_disable_ports()
2502 { .compatible = "nvidia,tegra186-pcie", .data = &tegra186_pcie },
2503 { .compatible = "nvidia,tegra210-pcie", .data = &tegra210_pcie },
2504 { .compatible = "nvidia,tegra124-pcie", .data = &tegra124_pcie },
2505 { .compatible = "nvidia,tegra30-pcie", .data = &tegra30_pcie },
2506 { .compatible = "nvidia,tegra20-pcie", .data = &tegra20_pcie },
2512 struct tegra_pcie *pcie = s->private; in tegra_pcie_ports_seq_start() local
2514 if (list_empty(&pcie->ports)) in tegra_pcie_ports_seq_start()
2519 return seq_list_start(&pcie->ports, *pos); in tegra_pcie_ports_seq_start()
2524 struct tegra_pcie *pcie = s->private; in tegra_pcie_ports_seq_next() local
2526 return seq_list_next(v, &pcie->ports, pos); in tegra_pcie_ports_seq_next()
2576 static void tegra_pcie_debugfs_exit(struct tegra_pcie *pcie) in tegra_pcie_debugfs_exit() argument
2578 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_debugfs_exit()
2579 pcie->debugfs = NULL; in tegra_pcie_debugfs_exit()
2582 static void tegra_pcie_debugfs_init(struct tegra_pcie *pcie) in tegra_pcie_debugfs_init() argument
2584 pcie->debugfs = debugfs_create_dir("pcie", NULL); in tegra_pcie_debugfs_init()
2586 debugfs_create_file("ports", S_IFREG | S_IRUGO, pcie->debugfs, pcie, in tegra_pcie_debugfs_init()
2594 struct tegra_pcie *pcie; in tegra_pcie_probe() local
2597 host = devm_pci_alloc_host_bridge(dev, sizeof(*pcie)); in tegra_pcie_probe()
2601 pcie = pci_host_bridge_priv(host); in tegra_pcie_probe()
2602 host->sysdata = pcie; in tegra_pcie_probe()
2603 platform_set_drvdata(pdev, pcie); in tegra_pcie_probe()
2605 pcie->soc = of_device_get_match_data(dev); in tegra_pcie_probe()
2606 INIT_LIST_HEAD(&pcie->ports); in tegra_pcie_probe()
2607 pcie->dev = dev; in tegra_pcie_probe()
2609 err = tegra_pcie_parse_dt(pcie); in tegra_pcie_probe()
2613 err = tegra_pcie_get_resources(pcie); in tegra_pcie_probe()
2619 err = tegra_pcie_msi_setup(pcie); in tegra_pcie_probe()
2625 pm_runtime_enable(pcie->dev); in tegra_pcie_probe()
2626 err = pm_runtime_get_sync(pcie->dev); in tegra_pcie_probe()
2628 dev_err(dev, "fail to enable pcie controller: %d\n", err); in tegra_pcie_probe()
2642 tegra_pcie_debugfs_init(pcie); in tegra_pcie_probe()
2647 pm_runtime_put_sync(pcie->dev); in tegra_pcie_probe()
2648 pm_runtime_disable(pcie->dev); in tegra_pcie_probe()
2649 tegra_pcie_msi_teardown(pcie); in tegra_pcie_probe()
2651 tegra_pcie_put_resources(pcie); in tegra_pcie_probe()
2657 struct tegra_pcie *pcie = platform_get_drvdata(pdev); in tegra_pcie_remove() local
2658 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); in tegra_pcie_remove()
2662 tegra_pcie_debugfs_exit(pcie); in tegra_pcie_remove()
2666 pm_runtime_put_sync(pcie->dev); in tegra_pcie_remove()
2667 pm_runtime_disable(pcie->dev); in tegra_pcie_remove()
2670 tegra_pcie_msi_teardown(pcie); in tegra_pcie_remove()
2672 tegra_pcie_put_resources(pcie); in tegra_pcie_remove()
2674 list_for_each_entry_safe(port, tmp, &pcie->ports, list) in tegra_pcie_remove()
2682 struct tegra_pcie *pcie = dev_get_drvdata(dev); in tegra_pcie_pm_suspend() local
2686 list_for_each_entry(port, &pcie->ports, list) in tegra_pcie_pm_suspend()
2689 tegra_pcie_disable_ports(pcie); in tegra_pcie_pm_suspend()
2695 tegra_pcie_disable_interrupts(pcie); in tegra_pcie_pm_suspend()
2697 if (pcie->soc->program_uphy) { in tegra_pcie_pm_suspend()
2698 err = tegra_pcie_phy_power_off(pcie); in tegra_pcie_pm_suspend()
2703 reset_control_assert(pcie->pex_rst); in tegra_pcie_pm_suspend()
2704 clk_disable_unprepare(pcie->pex_clk); in tegra_pcie_pm_suspend()
2707 tegra_pcie_disable_msi(pcie); in tegra_pcie_pm_suspend()
2710 tegra_pcie_power_off(pcie); in tegra_pcie_pm_suspend()
2717 struct tegra_pcie *pcie = dev_get_drvdata(dev); in tegra_pcie_pm_resume() local
2720 err = tegra_pcie_power_on(pcie); in tegra_pcie_pm_resume()
2722 dev_err(dev, "tegra pcie power on fail: %d\n", err); in tegra_pcie_pm_resume()
2728 dev_err(dev, "failed to disable PCIe IO DPD: %d\n", err); in tegra_pcie_pm_resume()
2732 tegra_pcie_enable_controller(pcie); in tegra_pcie_pm_resume()
2733 tegra_pcie_setup_translations(pcie); in tegra_pcie_pm_resume()
2736 tegra_pcie_enable_msi(pcie); in tegra_pcie_pm_resume()
2738 err = clk_prepare_enable(pcie->pex_clk); in tegra_pcie_pm_resume()
2744 reset_control_deassert(pcie->pex_rst); in tegra_pcie_pm_resume()
2746 if (pcie->soc->program_uphy) { in tegra_pcie_pm_resume()
2747 err = tegra_pcie_phy_power_on(pcie); in tegra_pcie_pm_resume()
2754 tegra_pcie_apply_pad_settings(pcie); in tegra_pcie_pm_resume()
2755 tegra_pcie_enable_ports(pcie); in tegra_pcie_pm_resume()
2760 reset_control_assert(pcie->pex_rst); in tegra_pcie_pm_resume()
2761 clk_disable_unprepare(pcie->pex_clk); in tegra_pcie_pm_resume()
2765 tegra_pcie_power_off(pcie); in tegra_pcie_pm_resume()
2778 .name = "tegra-pcie",