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
257 * entries, one entry per PCIe port. These field definitions and desired
362 struct tegra_pcie *pcie; member
375 static inline void afi_writel(struct tegra_pcie *pcie, u32 value, in afi_writel() argument
378 writel(value, pcie->afi + offset); in afi_writel()
381 static inline u32 afi_readl(struct tegra_pcie *pcie, unsigned long offset) in afi_readl() argument
383 return readl(pcie->afi + offset); in afi_readl()
386 static inline void pads_writel(struct tegra_pcie *pcie, u32 value, in pads_writel() argument
389 writel(value, pcie->pads + offset); in pads_writel()
392 static inline u32 pads_readl(struct tegra_pcie *pcie, unsigned long offset) in pads_readl() argument
394 return readl(pcie->pads + offset); in pads_readl()
399 * defined by PCIe. However it deviates a bit in how the 4 bits for extended
429 struct tegra_pcie *pcie = bus->sysdata; in tegra_pcie_map_bus() local
436 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_map_bus()
450 afi_writel(pcie, base, AFI_FPCI_BAR0); in tegra_pcie_map_bus()
453 addr = pcie->cfg + (offset & (SZ_4K - 1)); in tegra_pcie_map_bus()
487 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_port_get_pex_ctrl()
516 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_reset()
518 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_reset()
526 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_reset()
528 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_reset()
534 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_enable_rp_features()
572 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_program_ectl_settings()
620 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_apply_sw_fixup()
643 * PCIe link doesn't come up with few legacy PCIe endpoints if in tegra_pcie_apply_sw_fixup()
657 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_port_enable()
661 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_enable()
669 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_enable()
690 const struct tegra_pcie_soc *soc = port->pcie->soc; in tegra_pcie_port_disable()
694 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_disable()
696 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_disable()
699 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_disable()
705 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_disable()
707 /* disable PCIe port and set CLKREQ# as GPIO to allow PLLE power down */ in tegra_pcie_port_disable()
708 value = afi_readl(port->pcie, AFI_PCIE_CONFIG); in tegra_pcie_port_disable()
711 afi_writel(port->pcie, value, AFI_PCIE_CONFIG); in tegra_pcie_port_disable()
716 struct tegra_pcie *pcie = port->pcie; in tegra_pcie_port_free() local
717 struct device *dev = pcie->dev; in tegra_pcie_port_free()
726 /* Tegra PCIE root complex wrongly reports device class */
736 /* Tegra20 and Tegra30 PCIE requires relaxed ordering */
748 struct tegra_pcie *pcie = pdev->bus->sysdata; in tegra_pcie_map_irq() local
755 irq = pcie->irq; in tegra_pcie_map_irq()
779 struct tegra_pcie *pcie = arg; in tegra_pcie_isr() local
780 struct device *dev = pcie->dev; in tegra_pcie_isr()
783 code = afi_readl(pcie, AFI_INTR_CODE) & AFI_INTR_CODE_MASK; in tegra_pcie_isr()
784 signature = afi_readl(pcie, AFI_INTR_SIGNATURE); in tegra_pcie_isr()
785 afi_writel(pcie, 0, AFI_INTR_CODE); in tegra_pcie_isr()
804 u32 fpci = afi_readl(pcie, AFI_UPPER_FPCI_ADDRESS) & 0xff; in tegra_pcie_isr()
824 static void tegra_pcie_setup_translations(struct tegra_pcie *pcie) in tegra_pcie_setup_translations() argument
828 struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); in tegra_pcie_setup_translations()
831 size = resource_size(&pcie->cs); in tegra_pcie_setup_translations()
832 afi_writel(pcie, pcie->cs.start, AFI_AXI_BAR0_START); in tegra_pcie_setup_translations()
833 afi_writel(pcie, size >> 12, AFI_AXI_BAR0_SZ); in tegra_pcie_setup_translations()
846 afi_writel(pcie, axi_address, AFI_AXI_BAR1_START); in tegra_pcie_setup_translations()
847 afi_writel(pcie, size >> 12, AFI_AXI_BAR1_SZ); in tegra_pcie_setup_translations()
848 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR1); in tegra_pcie_setup_translations()
856 afi_writel(pcie, axi_address, AFI_AXI_BAR2_START); in tegra_pcie_setup_translations()
857 afi_writel(pcie, size >> 12, AFI_AXI_BAR2_SZ); in tegra_pcie_setup_translations()
858 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR2); in tegra_pcie_setup_translations()
862 afi_writel(pcie, axi_address, AFI_AXI_BAR3_START); in tegra_pcie_setup_translations()
863 afi_writel(pcie, size >> 12, AFI_AXI_BAR3_SZ); in tegra_pcie_setup_translations()
864 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR3); in tegra_pcie_setup_translations()
871 afi_writel(pcie, 0, AFI_AXI_BAR4_START); in tegra_pcie_setup_translations()
872 afi_writel(pcie, 0, AFI_AXI_BAR4_SZ); in tegra_pcie_setup_translations()
873 afi_writel(pcie, 0, AFI_FPCI_BAR4); in tegra_pcie_setup_translations()
875 afi_writel(pcie, 0, AFI_AXI_BAR5_START); in tegra_pcie_setup_translations()
876 afi_writel(pcie, 0, AFI_AXI_BAR5_SZ); in tegra_pcie_setup_translations()
877 afi_writel(pcie, 0, AFI_FPCI_BAR5); in tegra_pcie_setup_translations()
879 if (pcie->soc->has_cache_bars) { in tegra_pcie_setup_translations()
881 afi_writel(pcie, 0, AFI_CACHE_BAR0_ST); in tegra_pcie_setup_translations()
882 afi_writel(pcie, 0, AFI_CACHE_BAR0_SZ); in tegra_pcie_setup_translations()
883 afi_writel(pcie, 0, AFI_CACHE_BAR1_ST); in tegra_pcie_setup_translations()
884 afi_writel(pcie, 0, AFI_CACHE_BAR1_SZ); in tegra_pcie_setup_translations()
888 afi_writel(pcie, 0, AFI_MSI_FPCI_BAR_ST); in tegra_pcie_setup_translations()
889 afi_writel(pcie, 0, AFI_MSI_BAR_SZ); in tegra_pcie_setup_translations()
890 afi_writel(pcie, 0, AFI_MSI_AXI_BAR_ST); in tegra_pcie_setup_translations()
891 afi_writel(pcie, 0, AFI_MSI_BAR_SZ); in tegra_pcie_setup_translations()
894 static int tegra_pcie_pll_wait(struct tegra_pcie *pcie, unsigned long timeout) in tegra_pcie_pll_wait() argument
896 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_pll_wait()
902 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_pll_wait()
910 static int tegra_pcie_phy_enable(struct tegra_pcie *pcie) in tegra_pcie_phy_enable() argument
912 struct device *dev = pcie->dev; in tegra_pcie_phy_enable()
913 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_phy_enable()
917 /* initialize internal PHY, enable up to 16 PCIE lanes */ in tegra_pcie_phy_enable()
918 pads_writel(pcie, 0x0, PADS_CTL_SEL); in tegra_pcie_phy_enable()
921 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
923 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
929 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
932 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
935 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
937 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
942 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
944 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
947 err = tegra_pcie_pll_wait(pcie, 500); in tegra_pcie_phy_enable()
954 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
956 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
959 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
961 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
966 static int tegra_pcie_phy_disable(struct tegra_pcie *pcie) in tegra_pcie_phy_disable() argument
968 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_phy_disable()
972 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_disable()
974 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_disable()
977 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_disable()
979 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_disable()
982 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_disable()
984 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_disable()
993 struct device *dev = port->pcie->dev; in tegra_pcie_port_phy_power_on()
1010 struct device *dev = port->pcie->dev; in tegra_pcie_port_phy_power_off()
1026 static int tegra_pcie_phy_power_on(struct tegra_pcie *pcie) in tegra_pcie_phy_power_on() argument
1028 struct device *dev = pcie->dev; in tegra_pcie_phy_power_on()
1032 if (pcie->legacy_phy) { in tegra_pcie_phy_power_on()
1033 if (pcie->phy) in tegra_pcie_phy_power_on()
1034 err = phy_power_on(pcie->phy); in tegra_pcie_phy_power_on()
1036 err = tegra_pcie_phy_enable(pcie); in tegra_pcie_phy_power_on()
1044 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_phy_power_on()
1048 "failed to power on PCIe port %u PHY: %d\n", in tegra_pcie_phy_power_on()
1057 static int tegra_pcie_phy_power_off(struct tegra_pcie *pcie) in tegra_pcie_phy_power_off() argument
1059 struct device *dev = pcie->dev; in tegra_pcie_phy_power_off()
1063 if (pcie->legacy_phy) { in tegra_pcie_phy_power_off()
1064 if (pcie->phy) in tegra_pcie_phy_power_off()
1065 err = phy_power_off(pcie->phy); in tegra_pcie_phy_power_off()
1067 err = tegra_pcie_phy_disable(pcie); in tegra_pcie_phy_power_off()
1075 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_phy_power_off()
1079 "failed to power off PCIe port %u PHY: %d\n", in tegra_pcie_phy_power_off()
1088 static void tegra_pcie_enable_controller(struct tegra_pcie *pcie) in tegra_pcie_enable_controller() argument
1090 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_enable_controller()
1095 if (pcie->phy) { in tegra_pcie_enable_controller()
1096 value = afi_readl(pcie, AFI_PLLE_CONTROL); in tegra_pcie_enable_controller()
1099 afi_writel(pcie, value, AFI_PLLE_CONTROL); in tegra_pcie_enable_controller()
1102 /* power down PCIe slot clock bias pad */ in tegra_pcie_enable_controller()
1104 afi_writel(pcie, 0, AFI_PEXBIAS_CTRL_0); in tegra_pcie_enable_controller()
1107 value = afi_readl(pcie, AFI_PCIE_CONFIG); in tegra_pcie_enable_controller()
1109 value |= AFI_PCIE_CONFIG_PCIE_DISABLE_ALL | pcie->xbar_config; in tegra_pcie_enable_controller()
1112 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_enable_controller()
1117 afi_writel(pcie, value, AFI_PCIE_CONFIG); in tegra_pcie_enable_controller()
1120 value = afi_readl(pcie, AFI_FUSE); in tegra_pcie_enable_controller()
1122 afi_writel(pcie, value, AFI_FUSE); in tegra_pcie_enable_controller()
1124 value = afi_readl(pcie, AFI_FUSE); in tegra_pcie_enable_controller()
1126 afi_writel(pcie, value, AFI_FUSE); in tegra_pcie_enable_controller()
1129 /* Disable AFI dynamic clock gating and enable PCIe */ in tegra_pcie_enable_controller()
1130 value = afi_readl(pcie, AFI_CONFIGURATION); in tegra_pcie_enable_controller()
1133 afi_writel(pcie, value, AFI_CONFIGURATION); in tegra_pcie_enable_controller()
1142 afi_writel(pcie, value, AFI_AFI_INTR_ENABLE); in tegra_pcie_enable_controller()
1143 afi_writel(pcie, 0xffffffff, AFI_SM_INTR_ENABLE); in tegra_pcie_enable_controller()
1146 afi_writel(pcie, AFI_INTR_MASK_INT_MASK, AFI_INTR_MASK); in tegra_pcie_enable_controller()
1149 afi_writel(pcie, 0, AFI_FPCI_ERROR_MASKS); in tegra_pcie_enable_controller()
1152 static void tegra_pcie_power_off(struct tegra_pcie *pcie) in tegra_pcie_power_off() argument
1154 struct device *dev = pcie->dev; in tegra_pcie_power_off()
1155 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_power_off()
1158 reset_control_assert(pcie->afi_rst); in tegra_pcie_power_off()
1160 clk_disable_unprepare(pcie->pll_e); in tegra_pcie_power_off()
1162 clk_disable_unprepare(pcie->cml_clk); in tegra_pcie_power_off()
1163 clk_disable_unprepare(pcie->afi_clk); in tegra_pcie_power_off()
1168 err = regulator_bulk_disable(pcie->num_supplies, pcie->supplies); in tegra_pcie_power_off()
1173 static int tegra_pcie_power_on(struct tegra_pcie *pcie) in tegra_pcie_power_on() argument
1175 struct device *dev = pcie->dev; in tegra_pcie_power_on()
1176 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_power_on()
1179 reset_control_assert(pcie->pcie_xrst); in tegra_pcie_power_on()
1180 reset_control_assert(pcie->afi_rst); in tegra_pcie_power_on()
1181 reset_control_assert(pcie->pex_rst); in tegra_pcie_power_on()
1187 err = regulator_bulk_enable(pcie->num_supplies, pcie->supplies); in tegra_pcie_power_on()
1204 err = clk_prepare_enable(pcie->afi_clk); in tegra_pcie_power_on()
1211 err = clk_prepare_enable(pcie->cml_clk); in tegra_pcie_power_on()
1218 err = clk_prepare_enable(pcie->pll_e); in tegra_pcie_power_on()
1224 reset_control_deassert(pcie->afi_rst); in tegra_pcie_power_on()
1230 clk_disable_unprepare(pcie->cml_clk); in tegra_pcie_power_on()
1232 clk_disable_unprepare(pcie->afi_clk); in tegra_pcie_power_on()
1237 regulator_bulk_disable(pcie->num_supplies, pcie->supplies); in tegra_pcie_power_on()
1242 static void tegra_pcie_apply_pad_settings(struct tegra_pcie *pcie) in tegra_pcie_apply_pad_settings() argument
1244 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_apply_pad_settings()
1247 pads_writel(pcie, soc->pads_refclk_cfg0, PADS_REFCLK_CFG0); in tegra_pcie_apply_pad_settings()
1250 pads_writel(pcie, soc->pads_refclk_cfg1, PADS_REFCLK_CFG1); in tegra_pcie_apply_pad_settings()
1253 static int tegra_pcie_clocks_get(struct tegra_pcie *pcie) in tegra_pcie_clocks_get() argument
1255 struct device *dev = pcie->dev; in tegra_pcie_clocks_get()
1256 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_clocks_get()
1258 pcie->pex_clk = devm_clk_get(dev, "pex"); in tegra_pcie_clocks_get()
1259 if (IS_ERR(pcie->pex_clk)) in tegra_pcie_clocks_get()
1260 return PTR_ERR(pcie->pex_clk); in tegra_pcie_clocks_get()
1262 pcie->afi_clk = devm_clk_get(dev, "afi"); in tegra_pcie_clocks_get()
1263 if (IS_ERR(pcie->afi_clk)) in tegra_pcie_clocks_get()
1264 return PTR_ERR(pcie->afi_clk); in tegra_pcie_clocks_get()
1266 pcie->pll_e = devm_clk_get(dev, "pll_e"); in tegra_pcie_clocks_get()
1267 if (IS_ERR(pcie->pll_e)) in tegra_pcie_clocks_get()
1268 return PTR_ERR(pcie->pll_e); in tegra_pcie_clocks_get()
1271 pcie->cml_clk = devm_clk_get(dev, "cml"); in tegra_pcie_clocks_get()
1272 if (IS_ERR(pcie->cml_clk)) in tegra_pcie_clocks_get()
1273 return PTR_ERR(pcie->cml_clk); in tegra_pcie_clocks_get()
1279 static int tegra_pcie_resets_get(struct tegra_pcie *pcie) in tegra_pcie_resets_get() argument
1281 struct device *dev = pcie->dev; in tegra_pcie_resets_get()
1283 pcie->pex_rst = devm_reset_control_get_exclusive(dev, "pex"); in tegra_pcie_resets_get()
1284 if (IS_ERR(pcie->pex_rst)) in tegra_pcie_resets_get()
1285 return PTR_ERR(pcie->pex_rst); in tegra_pcie_resets_get()
1287 pcie->afi_rst = devm_reset_control_get_exclusive(dev, "afi"); in tegra_pcie_resets_get()
1288 if (IS_ERR(pcie->afi_rst)) in tegra_pcie_resets_get()
1289 return PTR_ERR(pcie->afi_rst); in tegra_pcie_resets_get()
1291 pcie->pcie_xrst = devm_reset_control_get_exclusive(dev, "pcie_x"); in tegra_pcie_resets_get()
1292 if (IS_ERR(pcie->pcie_xrst)) in tegra_pcie_resets_get()
1293 return PTR_ERR(pcie->pcie_xrst); in tegra_pcie_resets_get()
1298 static int tegra_pcie_phys_get_legacy(struct tegra_pcie *pcie) in tegra_pcie_phys_get_legacy() argument
1300 struct device *dev = pcie->dev; in tegra_pcie_phys_get_legacy()
1303 pcie->phy = devm_phy_optional_get(dev, "pcie"); in tegra_pcie_phys_get_legacy()
1304 if (IS_ERR(pcie->phy)) { in tegra_pcie_phys_get_legacy()
1305 err = PTR_ERR(pcie->phy); in tegra_pcie_phys_get_legacy()
1310 err = phy_init(pcie->phy); in tegra_pcie_phys_get_legacy()
1316 pcie->legacy_phy = true; in tegra_pcie_phys_get_legacy()
1344 struct device *dev = port->pcie->dev; in tegra_pcie_port_get_phys()
1354 phy = devm_of_phy_optional_get_index(dev, port->np, "pcie", i); in tegra_pcie_port_get_phys()
1374 static int tegra_pcie_phys_get(struct tegra_pcie *pcie) in tegra_pcie_phys_get() argument
1376 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_phys_get()
1377 struct device_node *np = pcie->dev->of_node; in tegra_pcie_phys_get()
1382 return tegra_pcie_phys_get_legacy(pcie); in tegra_pcie_phys_get()
1384 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_phys_get()
1393 static void tegra_pcie_phys_put(struct tegra_pcie *pcie) in tegra_pcie_phys_put() argument
1396 struct device *dev = pcie->dev; in tegra_pcie_phys_put()
1399 if (pcie->legacy_phy) { in tegra_pcie_phys_put()
1400 err = phy_exit(pcie->phy); in tegra_pcie_phys_put()
1406 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_phys_put()
1416 static int tegra_pcie_get_resources(struct tegra_pcie *pcie) in tegra_pcie_get_resources() argument
1418 struct device *dev = pcie->dev; in tegra_pcie_get_resources()
1421 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_get_resources()
1424 err = tegra_pcie_clocks_get(pcie); in tegra_pcie_get_resources()
1430 err = tegra_pcie_resets_get(pcie); in tegra_pcie_get_resources()
1437 err = tegra_pcie_phys_get(pcie); in tegra_pcie_get_resources()
1444 pcie->pads = devm_platform_ioremap_resource_byname(pdev, "pads"); in tegra_pcie_get_resources()
1445 if (IS_ERR(pcie->pads)) { in tegra_pcie_get_resources()
1446 err = PTR_ERR(pcie->pads); in tegra_pcie_get_resources()
1450 pcie->afi = devm_platform_ioremap_resource_byname(pdev, "afi"); in tegra_pcie_get_resources()
1451 if (IS_ERR(pcie->afi)) { in tegra_pcie_get_resources()
1452 err = PTR_ERR(pcie->afi); in tegra_pcie_get_resources()
1463 pcie->cs = *res; in tegra_pcie_get_resources()
1466 pcie->cs.end = pcie->cs.start + SZ_4K - 1; in tegra_pcie_get_resources()
1468 pcie->cfg = devm_ioremap_resource(dev, &pcie->cs); in tegra_pcie_get_resources()
1469 if (IS_ERR(pcie->cfg)) { in tegra_pcie_get_resources()
1470 err = PTR_ERR(pcie->cfg); in tegra_pcie_get_resources()
1479 pcie->irq = err; in tegra_pcie_get_resources()
1481 err = request_irq(pcie->irq, tegra_pcie_isr, IRQF_SHARED, "PCIE", pcie); in tegra_pcie_get_resources()
1491 tegra_pcie_phys_put(pcie); in tegra_pcie_get_resources()
1496 static int tegra_pcie_put_resources(struct tegra_pcie *pcie) in tegra_pcie_put_resources() argument
1498 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_put_resources()
1500 if (pcie->irq > 0) in tegra_pcie_put_resources()
1501 free_irq(pcie->irq, pcie); in tegra_pcie_put_resources()
1504 tegra_pcie_phys_put(pcie); in tegra_pcie_put_resources()
1511 struct tegra_pcie *pcie = port->pcie; in tegra_pcie_pme_turnoff() local
1512 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_pme_turnoff()
1517 val = afi_readl(pcie, AFI_PCIE_PME); in tegra_pcie_pme_turnoff()
1519 afi_writel(pcie, val, AFI_PCIE_PME); in tegra_pcie_pme_turnoff()
1522 err = readl_poll_timeout(pcie->afi + AFI_PCIE_PME, val, in tegra_pcie_pme_turnoff()
1525 dev_err(pcie->dev, "PME Ack is not received on port: %d\n", in tegra_pcie_pme_turnoff()
1530 val = afi_readl(pcie, AFI_PCIE_PME); in tegra_pcie_pme_turnoff()
1532 afi_writel(pcie, val, AFI_PCIE_PME); in tegra_pcie_pme_turnoff()
1537 struct tegra_pcie *pcie = irq_desc_get_handler_data(desc); in tegra_pcie_msi_irq() local
1539 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_msi_irq()
1540 struct device *dev = pcie->dev; in tegra_pcie_msi_irq()
1546 unsigned long reg = afi_readl(pcie, AFI_MSI_VEC(i)); in tegra_pcie_msi_irq()
1560 afi_writel(pcie, BIT(index % 32), AFI_MSI_VEC(index)); in tegra_pcie_msi_irq()
1564 reg = afi_readl(pcie, AFI_MSI_VEC(i)); in tegra_pcie_msi_irq()
1589 .name = "Tegra PCIe MSI",
1598 struct tegra_pcie *pcie = msi_to_pcie(msi); in tegra_msi_irq_ack() local
1602 afi_writel(pcie, BIT(d->hwirq % 32), AFI_MSI_VEC(index)); in tegra_msi_irq_ack()
1608 struct tegra_pcie *pcie = msi_to_pcie(msi); in tegra_msi_irq_mask() local
1614 value = afi_readl(pcie, AFI_MSI_EN_VEC(index)); in tegra_msi_irq_mask()
1616 afi_writel(pcie, value, AFI_MSI_EN_VEC(index)); in tegra_msi_irq_mask()
1623 struct tegra_pcie *pcie = msi_to_pcie(msi); in tegra_msi_irq_unmask() local
1629 value = afi_readl(pcie, AFI_MSI_EN_VEC(index)); in tegra_msi_irq_unmask()
1631 afi_writel(pcie, value, AFI_MSI_EN_VEC(index)); in tegra_msi_irq_unmask()
1710 struct tegra_pcie *pcie = msi_to_pcie(msi); in tegra_allocate_domains() local
1711 struct fwnode_handle *fwnode = dev_fwnode(pcie->dev); in tegra_allocate_domains()
1717 dev_err(pcie->dev, "failed to create IRQ domain\n"); in tegra_allocate_domains()
1724 dev_err(pcie->dev, "failed to create MSI domain\n"); in tegra_allocate_domains()
1740 static int tegra_pcie_msi_setup(struct tegra_pcie *pcie) in tegra_pcie_msi_setup() argument
1742 struct platform_device *pdev = to_platform_device(pcie->dev); in tegra_pcie_msi_setup()
1743 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_msi_setup()
1744 struct device *dev = pcie->dev; in tegra_pcie_msi_setup()
1762 irq_set_chained_handler_and_data(msi->irq, tegra_pcie_msi_irq, pcie); in tegra_pcie_msi_setup()
1764 /* Though the PCIe controller can address >32-bit address space, to in tegra_pcie_msi_setup()
1794 static void tegra_pcie_enable_msi(struct tegra_pcie *pcie) in tegra_pcie_enable_msi() argument
1796 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_enable_msi()
1797 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_enable_msi()
1801 afi_writel(pcie, msi->phys >> soc->msi_base_shift, AFI_MSI_FPCI_BAR_ST); in tegra_pcie_enable_msi()
1802 afi_writel(pcie, msi->phys, AFI_MSI_AXI_BAR_ST); in tegra_pcie_enable_msi()
1804 afi_writel(pcie, 1, AFI_MSI_BAR_SZ); in tegra_pcie_enable_msi()
1809 afi_writel(pcie, msi_state[i], AFI_MSI_EN_VEC(i)); in tegra_pcie_enable_msi()
1812 reg = afi_readl(pcie, AFI_INTR_MASK); in tegra_pcie_enable_msi()
1814 afi_writel(pcie, reg, AFI_INTR_MASK); in tegra_pcie_enable_msi()
1817 static void tegra_pcie_msi_teardown(struct tegra_pcie *pcie) in tegra_pcie_msi_teardown() argument
1819 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_msi_teardown()
1822 dma_free_attrs(pcie->dev, PAGE_SIZE, msi->virt, msi->phys, in tegra_pcie_msi_teardown()
1837 static int tegra_pcie_disable_msi(struct tegra_pcie *pcie) in tegra_pcie_disable_msi() argument
1842 value = afi_readl(pcie, AFI_INTR_MASK); in tegra_pcie_disable_msi()
1844 afi_writel(pcie, value, AFI_INTR_MASK); in tegra_pcie_disable_msi()
1849 static void tegra_pcie_disable_interrupts(struct tegra_pcie *pcie) in tegra_pcie_disable_interrupts() argument
1853 value = afi_readl(pcie, AFI_INTR_MASK); in tegra_pcie_disable_interrupts()
1855 afi_writel(pcie, value, AFI_INTR_MASK); in tegra_pcie_disable_interrupts()
1858 static int tegra_pcie_get_xbar_config(struct tegra_pcie *pcie, u32 lanes, in tegra_pcie_get_xbar_config() argument
1861 struct device *dev = pcie->dev; in tegra_pcie_get_xbar_config()
1864 if (of_device_is_compatible(np, "nvidia,tegra186-pcie")) { in tegra_pcie_get_xbar_config()
1888 } else if (of_device_is_compatible(np, "nvidia,tegra124-pcie") || in tegra_pcie_get_xbar_config()
1889 of_device_is_compatible(np, "nvidia,tegra210-pcie")) { in tegra_pcie_get_xbar_config()
1901 } else if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) { in tegra_pcie_get_xbar_config()
1918 } else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) { in tegra_pcie_get_xbar_config()
1964 static int tegra_pcie_get_legacy_regulators(struct tegra_pcie *pcie) in tegra_pcie_get_legacy_regulators() argument
1966 struct device *dev = pcie->dev; in tegra_pcie_get_legacy_regulators()
1969 if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) in tegra_pcie_get_legacy_regulators()
1970 pcie->num_supplies = 3; in tegra_pcie_get_legacy_regulators()
1971 else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) in tegra_pcie_get_legacy_regulators()
1972 pcie->num_supplies = 2; in tegra_pcie_get_legacy_regulators()
1974 if (pcie->num_supplies == 0) { in tegra_pcie_get_legacy_regulators()
1979 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, in tegra_pcie_get_legacy_regulators()
1980 sizeof(*pcie->supplies), in tegra_pcie_get_legacy_regulators()
1982 if (!pcie->supplies) in tegra_pcie_get_legacy_regulators()
1985 pcie->supplies[0].supply = "pex-clk"; in tegra_pcie_get_legacy_regulators()
1986 pcie->supplies[1].supply = "vdd"; in tegra_pcie_get_legacy_regulators()
1988 if (pcie->num_supplies > 2) in tegra_pcie_get_legacy_regulators()
1989 pcie->supplies[2].supply = "avdd"; in tegra_pcie_get_legacy_regulators()
1991 return devm_regulator_bulk_get(dev, pcie->num_supplies, pcie->supplies); in tegra_pcie_get_legacy_regulators()
2003 static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) in tegra_pcie_get_regulators() argument
2005 struct device *dev = pcie->dev; in tegra_pcie_get_regulators()
2009 if (of_device_is_compatible(np, "nvidia,tegra186-pcie")) { in tegra_pcie_get_regulators()
2010 pcie->num_supplies = 4; in tegra_pcie_get_regulators()
2012 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2013 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2015 if (!pcie->supplies) in tegra_pcie_get_regulators()
2018 pcie->supplies[i++].supply = "dvdd-pex"; in tegra_pcie_get_regulators()
2019 pcie->supplies[i++].supply = "hvdd-pex-pll"; in tegra_pcie_get_regulators()
2020 pcie->supplies[i++].supply = "hvdd-pex"; in tegra_pcie_get_regulators()
2021 pcie->supplies[i++].supply = "vddio-pexctl-aud"; in tegra_pcie_get_regulators()
2022 } else if (of_device_is_compatible(np, "nvidia,tegra210-pcie")) { in tegra_pcie_get_regulators()
2023 pcie->num_supplies = 3; in tegra_pcie_get_regulators()
2025 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2026 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2028 if (!pcie->supplies) in tegra_pcie_get_regulators()
2031 pcie->supplies[i++].supply = "hvddio-pex"; in tegra_pcie_get_regulators()
2032 pcie->supplies[i++].supply = "dvddio-pex"; in tegra_pcie_get_regulators()
2033 pcie->supplies[i++].supply = "vddio-pex-ctl"; in tegra_pcie_get_regulators()
2034 } else if (of_device_is_compatible(np, "nvidia,tegra124-pcie")) { in tegra_pcie_get_regulators()
2035 pcie->num_supplies = 4; in tegra_pcie_get_regulators()
2037 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2038 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2040 if (!pcie->supplies) in tegra_pcie_get_regulators()
2043 pcie->supplies[i++].supply = "avddio-pex"; in tegra_pcie_get_regulators()
2044 pcie->supplies[i++].supply = "dvddio-pex"; in tegra_pcie_get_regulators()
2045 pcie->supplies[i++].supply = "hvdd-pex"; in tegra_pcie_get_regulators()
2046 pcie->supplies[i++].supply = "vddio-pex-ctl"; in tegra_pcie_get_regulators()
2047 } else if (of_device_is_compatible(np, "nvidia,tegra30-pcie")) { in tegra_pcie_get_regulators()
2058 pcie->num_supplies = 4 + (need_pexa ? 2 : 0) + in tegra_pcie_get_regulators()
2061 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2062 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2064 if (!pcie->supplies) in tegra_pcie_get_regulators()
2067 pcie->supplies[i++].supply = "avdd-pex-pll"; in tegra_pcie_get_regulators()
2068 pcie->supplies[i++].supply = "hvdd-pex"; in tegra_pcie_get_regulators()
2069 pcie->supplies[i++].supply = "vddio-pex-ctl"; in tegra_pcie_get_regulators()
2070 pcie->supplies[i++].supply = "avdd-plle"; in tegra_pcie_get_regulators()
2073 pcie->supplies[i++].supply = "avdd-pexa"; in tegra_pcie_get_regulators()
2074 pcie->supplies[i++].supply = "vdd-pexa"; in tegra_pcie_get_regulators()
2078 pcie->supplies[i++].supply = "avdd-pexb"; in tegra_pcie_get_regulators()
2079 pcie->supplies[i++].supply = "vdd-pexb"; in tegra_pcie_get_regulators()
2081 } else if (of_device_is_compatible(np, "nvidia,tegra20-pcie")) { in tegra_pcie_get_regulators()
2082 pcie->num_supplies = 5; in tegra_pcie_get_regulators()
2084 pcie->supplies = devm_kcalloc(dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2085 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
2087 if (!pcie->supplies) in tegra_pcie_get_regulators()
2090 pcie->supplies[0].supply = "avdd-pex"; in tegra_pcie_get_regulators()
2091 pcie->supplies[1].supply = "vdd-pex"; in tegra_pcie_get_regulators()
2092 pcie->supplies[2].supply = "avdd-pex-pll"; in tegra_pcie_get_regulators()
2093 pcie->supplies[3].supply = "avdd-plle"; in tegra_pcie_get_regulators()
2094 pcie->supplies[4].supply = "vddio-pex-clk"; in tegra_pcie_get_regulators()
2097 if (of_regulator_bulk_available(dev->of_node, pcie->supplies, in tegra_pcie_get_regulators()
2098 pcie->num_supplies)) in tegra_pcie_get_regulators()
2099 return devm_regulator_bulk_get(dev, pcie->num_supplies, in tegra_pcie_get_regulators()
2100 pcie->supplies); in tegra_pcie_get_regulators()
2109 devm_kfree(dev, pcie->supplies); in tegra_pcie_get_regulators()
2110 pcie->num_supplies = 0; in tegra_pcie_get_regulators()
2112 return tegra_pcie_get_legacy_regulators(pcie); in tegra_pcie_get_regulators()
2115 static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) in tegra_pcie_parse_dt() argument
2117 struct device *dev = pcie->dev; in tegra_pcie_parse_dt()
2119 const struct tegra_pcie_soc *soc = pcie->soc; in tegra_pcie_parse_dt()
2185 rp->pcie = pcie; in tegra_pcie_parse_dt()
2220 list_add_tail(&rp->list, &pcie->ports); in tegra_pcie_parse_dt()
2223 err = tegra_pcie_get_xbar_config(pcie, lanes, &pcie->xbar_config); in tegra_pcie_parse_dt()
2229 err = tegra_pcie_get_regulators(pcie, mask); in tegra_pcie_parse_dt()
2241 * FIXME: If there are no PCIe cards attached, then calling this function
2248 struct device *dev = port->pcie->dev; in tegra_pcie_port_check_link()
2293 static void tegra_pcie_change_link_speed(struct tegra_pcie *pcie) in tegra_pcie_change_link_speed() argument
2295 struct device *dev = pcie->dev; in tegra_pcie_change_link_speed()
2300 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_change_link_speed()
2327 dev_warn(dev, "PCIe port %u link is in recovery\n", in tegra_pcie_change_link_speed()
2351 static void tegra_pcie_enable_ports(struct tegra_pcie *pcie) in tegra_pcie_enable_ports() argument
2353 struct device *dev = pcie->dev; in tegra_pcie_enable_ports()
2356 list_for_each_entry_safe(port, tmp, &pcie->ports, list) { in tegra_pcie_enable_ports()
2364 reset_control_deassert(pcie->pcie_xrst); in tegra_pcie_enable_ports()
2366 list_for_each_entry_safe(port, tmp, &pcie->ports, list) { in tegra_pcie_enable_ports()
2376 if (pcie->soc->has_gen2) in tegra_pcie_enable_ports()
2377 tegra_pcie_change_link_speed(pcie); in tegra_pcie_enable_ports()
2380 static void tegra_pcie_disable_ports(struct tegra_pcie *pcie) in tegra_pcie_disable_ports() argument
2384 reset_control_assert(pcie->pcie_xrst); in tegra_pcie_disable_ports()
2386 list_for_each_entry_safe(port, tmp, &pcie->ports, list) in tegra_pcie_disable_ports()
2531 { .compatible = "nvidia,tegra186-pcie", .data = &tegra186_pcie },
2532 { .compatible = "nvidia,tegra210-pcie", .data = &tegra210_pcie },
2533 { .compatible = "nvidia,tegra124-pcie", .data = &tegra124_pcie },
2534 { .compatible = "nvidia,tegra30-pcie", .data = &tegra30_pcie },
2535 { .compatible = "nvidia,tegra20-pcie", .data = &tegra20_pcie },
2542 struct tegra_pcie *pcie = s->private; in tegra_pcie_ports_seq_start() local
2544 if (list_empty(&pcie->ports)) in tegra_pcie_ports_seq_start()
2549 return seq_list_start(&pcie->ports, *pos); in tegra_pcie_ports_seq_start()
2554 struct tegra_pcie *pcie = s->private; in tegra_pcie_ports_seq_next() local
2556 return seq_list_next(v, &pcie->ports, pos); in tegra_pcie_ports_seq_next()
2606 static void tegra_pcie_debugfs_exit(struct tegra_pcie *pcie) in tegra_pcie_debugfs_exit() argument
2608 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_debugfs_exit()
2609 pcie->debugfs = NULL; in tegra_pcie_debugfs_exit()
2612 static void tegra_pcie_debugfs_init(struct tegra_pcie *pcie) in tegra_pcie_debugfs_init() argument
2614 pcie->debugfs = debugfs_create_dir("pcie", NULL); in tegra_pcie_debugfs_init()
2616 debugfs_create_file("ports", S_IFREG | S_IRUGO, pcie->debugfs, pcie, in tegra_pcie_debugfs_init()
2624 struct tegra_pcie *pcie; in tegra_pcie_probe() local
2627 host = devm_pci_alloc_host_bridge(dev, sizeof(*pcie)); in tegra_pcie_probe()
2631 pcie = pci_host_bridge_priv(host); in tegra_pcie_probe()
2632 host->sysdata = pcie; in tegra_pcie_probe()
2633 platform_set_drvdata(pdev, pcie); in tegra_pcie_probe()
2635 pcie->soc = of_device_get_match_data(dev); in tegra_pcie_probe()
2636 INIT_LIST_HEAD(&pcie->ports); in tegra_pcie_probe()
2637 pcie->dev = dev; in tegra_pcie_probe()
2639 err = tegra_pcie_parse_dt(pcie); in tegra_pcie_probe()
2643 err = tegra_pcie_get_resources(pcie); in tegra_pcie_probe()
2649 err = tegra_pcie_msi_setup(pcie); in tegra_pcie_probe()
2655 pm_runtime_enable(pcie->dev); in tegra_pcie_probe()
2656 err = pm_runtime_get_sync(pcie->dev); in tegra_pcie_probe()
2658 dev_err(dev, "fail to enable pcie controller: %d\n", err); in tegra_pcie_probe()
2672 tegra_pcie_debugfs_init(pcie); in tegra_pcie_probe()
2677 pm_runtime_put_sync(pcie->dev); in tegra_pcie_probe()
2678 pm_runtime_disable(pcie->dev); in tegra_pcie_probe()
2679 tegra_pcie_msi_teardown(pcie); in tegra_pcie_probe()
2681 tegra_pcie_put_resources(pcie); in tegra_pcie_probe()
2687 struct tegra_pcie *pcie = platform_get_drvdata(pdev); in tegra_pcie_remove() local
2688 struct pci_host_bridge *host = pci_host_bridge_from_priv(pcie); in tegra_pcie_remove()
2692 tegra_pcie_debugfs_exit(pcie); in tegra_pcie_remove()
2696 pm_runtime_put_sync(pcie->dev); in tegra_pcie_remove()
2697 pm_runtime_disable(pcie->dev); in tegra_pcie_remove()
2700 tegra_pcie_msi_teardown(pcie); in tegra_pcie_remove()
2702 tegra_pcie_put_resources(pcie); in tegra_pcie_remove()
2704 list_for_each_entry_safe(port, tmp, &pcie->ports, list) in tegra_pcie_remove()
2712 struct tegra_pcie *pcie = dev_get_drvdata(dev); in tegra_pcie_pm_suspend() local
2716 list_for_each_entry(port, &pcie->ports, list) in tegra_pcie_pm_suspend()
2719 tegra_pcie_disable_ports(pcie); in tegra_pcie_pm_suspend()
2725 tegra_pcie_disable_interrupts(pcie); in tegra_pcie_pm_suspend()
2727 if (pcie->soc->program_uphy) { in tegra_pcie_pm_suspend()
2728 err = tegra_pcie_phy_power_off(pcie); in tegra_pcie_pm_suspend()
2733 reset_control_assert(pcie->pex_rst); in tegra_pcie_pm_suspend()
2734 clk_disable_unprepare(pcie->pex_clk); in tegra_pcie_pm_suspend()
2737 tegra_pcie_disable_msi(pcie); in tegra_pcie_pm_suspend()
2740 tegra_pcie_power_off(pcie); in tegra_pcie_pm_suspend()
2747 struct tegra_pcie *pcie = dev_get_drvdata(dev); in tegra_pcie_pm_resume() local
2750 err = tegra_pcie_power_on(pcie); in tegra_pcie_pm_resume()
2752 dev_err(dev, "tegra pcie power on fail: %d\n", err); in tegra_pcie_pm_resume()
2758 dev_err(dev, "failed to disable PCIe IO DPD: %d\n", err); in tegra_pcie_pm_resume()
2762 tegra_pcie_enable_controller(pcie); in tegra_pcie_pm_resume()
2763 tegra_pcie_setup_translations(pcie); in tegra_pcie_pm_resume()
2766 tegra_pcie_enable_msi(pcie); in tegra_pcie_pm_resume()
2768 err = clk_prepare_enable(pcie->pex_clk); in tegra_pcie_pm_resume()
2774 reset_control_deassert(pcie->pex_rst); in tegra_pcie_pm_resume()
2776 if (pcie->soc->program_uphy) { in tegra_pcie_pm_resume()
2777 err = tegra_pcie_phy_power_on(pcie); in tegra_pcie_pm_resume()
2784 tegra_pcie_apply_pad_settings(pcie); in tegra_pcie_pm_resume()
2785 tegra_pcie_enable_ports(pcie); in tegra_pcie_pm_resume()
2790 reset_control_assert(pcie->pex_rst); in tegra_pcie_pm_resume()
2791 clk_disable_unprepare(pcie->pex_clk); in tegra_pcie_pm_resume()
2795 tegra_pcie_power_off(pcie); in tegra_pcie_pm_resume()
2807 .name = "tegra-pcie",