Lines Matching refs:pcie
309 struct tegra_pcie *pcie; member
328 static inline void afi_writel(struct tegra_pcie *pcie, u32 value, in afi_writel() argument
331 writel(value, pcie->afi + offset); in afi_writel()
334 static inline u32 afi_readl(struct tegra_pcie *pcie, unsigned long offset) in afi_readl() argument
336 return readl(pcie->afi + offset); in afi_readl()
339 static inline void pads_writel(struct tegra_pcie *pcie, u32 value, in pads_writel() argument
342 writel(value, pcie->pads + offset); in pads_writel()
345 static inline u32 pads_readl(struct tegra_pcie *pcie, unsigned long offset) in pads_readl() argument
347 return readl(pcie->pads + offset); in pads_readl()
382 static struct tegra_pcie_bus *tegra_pcie_bus_alloc(struct tegra_pcie *pcie, in tegra_pcie_bus_alloc() argument
387 phys_addr_t cs = pcie->cs->start; in tegra_pcie_bus_alloc()
414 dev_err(pcie->dev, "ioremap_page_range() failed: %d\n", in tegra_pcie_bus_alloc()
433 static void __iomem *tegra_pcie_bus_map(struct tegra_pcie *pcie, in tegra_pcie_bus_map() argument
438 list_for_each_entry(bus, &pcie->buses, list) in tegra_pcie_bus_map()
442 bus = tegra_pcie_bus_alloc(pcie, busnr); in tegra_pcie_bus_map()
446 list_add_tail(&bus->list, &pcie->buses); in tegra_pcie_bus_map()
455 struct tegra_pcie *pcie = sys_to_pcie(bus->sysdata); in tegra_pcie_conf_address() local
462 list_for_each_entry(port, &pcie->ports, list) { in tegra_pcie_conf_address()
469 addr = tegra_pcie_bus_map(pcie, bus->number); in tegra_pcie_conf_address()
471 dev_err(pcie->dev, in tegra_pcie_conf_address()
516 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_reset()
518 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_reset()
522 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_reset()
524 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_reset()
529 const struct tegra_pcie_soc_data *soc = port->pcie->soc_data; in tegra_pcie_port_enable()
534 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_enable()
542 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_enable()
549 const struct tegra_pcie_soc_data *soc = port->pcie->soc_data; in tegra_pcie_port_disable()
554 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_disable()
556 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_disable()
559 value = afi_readl(port->pcie, ctrl); in tegra_pcie_port_disable()
565 afi_writel(port->pcie, value, ctrl); in tegra_pcie_port_disable()
570 struct tegra_pcie *pcie = port->pcie; in tegra_pcie_port_free() local
572 devm_iounmap(pcie->dev, port->base); in tegra_pcie_port_free()
573 devm_release_mem_region(pcie->dev, port->regs.start, in tegra_pcie_port_free()
576 devm_kfree(pcie->dev, port); in tegra_pcie_port_free()
598 struct tegra_pcie *pcie = sys_to_pcie(sys); in tegra_pcie_setup() local
601 err = devm_request_resource(pcie->dev, &pcie->all, &pcie->mem); in tegra_pcie_setup()
605 err = devm_request_resource(pcie->dev, &pcie->all, &pcie->prefetch); in tegra_pcie_setup()
609 pci_add_resource_offset(&sys->resources, &pcie->mem, sys->mem_offset); in tegra_pcie_setup()
610 pci_add_resource_offset(&sys->resources, &pcie->prefetch, in tegra_pcie_setup()
612 pci_add_resource(&sys->resources, &pcie->busn); in tegra_pcie_setup()
614 pci_ioremap_io(pcie->pio.start, pcie->io.start); in tegra_pcie_setup()
621 struct tegra_pcie *pcie = sys_to_pcie(pdev->bus->sysdata); in tegra_pcie_map_irq() local
628 irq = pcie->irq; in tegra_pcie_map_irq()
652 struct tegra_pcie *pcie = arg; in tegra_pcie_isr() local
655 code = afi_readl(pcie, AFI_INTR_CODE) & AFI_INTR_CODE_MASK; in tegra_pcie_isr()
656 signature = afi_readl(pcie, AFI_INTR_SIGNATURE); in tegra_pcie_isr()
657 afi_writel(pcie, 0, AFI_INTR_CODE); in tegra_pcie_isr()
670 dev_dbg(pcie->dev, "%s, signature: %08x\n", err_msg[code], in tegra_pcie_isr()
673 dev_err(pcie->dev, "%s, signature: %08x\n", err_msg[code], in tegra_pcie_isr()
678 u32 fpci = afi_readl(pcie, AFI_UPPER_FPCI_ADDRESS) & 0xff; in tegra_pcie_isr()
682 dev_dbg(pcie->dev, " FPCI address: %10llx\n", address); in tegra_pcie_isr()
684 dev_err(pcie->dev, " FPCI address: %10llx\n", address); in tegra_pcie_isr()
698 static void tegra_pcie_setup_translations(struct tegra_pcie *pcie) in tegra_pcie_setup_translations() argument
704 size = resource_size(pcie->cs); in tegra_pcie_setup_translations()
705 axi_address = pcie->cs->start; in tegra_pcie_setup_translations()
706 afi_writel(pcie, axi_address, AFI_AXI_BAR0_START); in tegra_pcie_setup_translations()
707 afi_writel(pcie, size >> 12, AFI_AXI_BAR0_SZ); in tegra_pcie_setup_translations()
708 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR0); in tegra_pcie_setup_translations()
712 size = resource_size(&pcie->io); in tegra_pcie_setup_translations()
713 axi_address = pcie->io.start; in tegra_pcie_setup_translations()
714 afi_writel(pcie, axi_address, AFI_AXI_BAR1_START); in tegra_pcie_setup_translations()
715 afi_writel(pcie, size >> 12, AFI_AXI_BAR1_SZ); in tegra_pcie_setup_translations()
716 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR1); in tegra_pcie_setup_translations()
719 fpci_bar = (((pcie->prefetch.start >> 12) & 0x0fffffff) << 4) | 0x1; in tegra_pcie_setup_translations()
720 size = resource_size(&pcie->prefetch); in tegra_pcie_setup_translations()
721 axi_address = pcie->prefetch.start; in tegra_pcie_setup_translations()
722 afi_writel(pcie, axi_address, AFI_AXI_BAR2_START); in tegra_pcie_setup_translations()
723 afi_writel(pcie, size >> 12, AFI_AXI_BAR2_SZ); in tegra_pcie_setup_translations()
724 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR2); in tegra_pcie_setup_translations()
727 fpci_bar = (((pcie->mem.start >> 12) & 0x0fffffff) << 4) | 0x1; in tegra_pcie_setup_translations()
728 size = resource_size(&pcie->mem); in tegra_pcie_setup_translations()
729 axi_address = pcie->mem.start; in tegra_pcie_setup_translations()
730 afi_writel(pcie, axi_address, AFI_AXI_BAR3_START); in tegra_pcie_setup_translations()
731 afi_writel(pcie, size >> 12, AFI_AXI_BAR3_SZ); in tegra_pcie_setup_translations()
732 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR3); in tegra_pcie_setup_translations()
735 afi_writel(pcie, 0, AFI_AXI_BAR4_START); in tegra_pcie_setup_translations()
736 afi_writel(pcie, 0, AFI_AXI_BAR4_SZ); in tegra_pcie_setup_translations()
737 afi_writel(pcie, 0, AFI_FPCI_BAR4); in tegra_pcie_setup_translations()
739 afi_writel(pcie, 0, AFI_AXI_BAR5_START); in tegra_pcie_setup_translations()
740 afi_writel(pcie, 0, AFI_AXI_BAR5_SZ); in tegra_pcie_setup_translations()
741 afi_writel(pcie, 0, AFI_FPCI_BAR5); in tegra_pcie_setup_translations()
744 afi_writel(pcie, PHYS_OFFSET, AFI_CACHE_BAR0_ST); in tegra_pcie_setup_translations()
745 afi_writel(pcie, 0, AFI_CACHE_BAR0_SZ); in tegra_pcie_setup_translations()
746 afi_writel(pcie, 0, AFI_CACHE_BAR1_ST); in tegra_pcie_setup_translations()
747 afi_writel(pcie, 0, AFI_CACHE_BAR1_SZ); in tegra_pcie_setup_translations()
750 afi_writel(pcie, 0, AFI_MSI_FPCI_BAR_ST); in tegra_pcie_setup_translations()
751 afi_writel(pcie, 0, AFI_MSI_BAR_SZ); in tegra_pcie_setup_translations()
752 afi_writel(pcie, 0, AFI_MSI_AXI_BAR_ST); in tegra_pcie_setup_translations()
753 afi_writel(pcie, 0, AFI_MSI_BAR_SZ); in tegra_pcie_setup_translations()
756 static int tegra_pcie_pll_wait(struct tegra_pcie *pcie, unsigned long timeout) in tegra_pcie_pll_wait() argument
758 const struct tegra_pcie_soc_data *soc = pcie->soc_data; in tegra_pcie_pll_wait()
764 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_pll_wait()
772 static int tegra_pcie_phy_enable(struct tegra_pcie *pcie) in tegra_pcie_phy_enable() argument
774 const struct tegra_pcie_soc_data *soc = pcie->soc_data; in tegra_pcie_phy_enable()
779 pads_writel(pcie, 0x0, PADS_CTL_SEL); in tegra_pcie_phy_enable()
782 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
784 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
790 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
793 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
796 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
798 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
803 value = pads_readl(pcie, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
805 pads_writel(pcie, value, soc->pads_pll_ctl); in tegra_pcie_phy_enable()
809 pads_writel(pcie, value, PADS_REFCLK_CFG0); in tegra_pcie_phy_enable()
811 pads_writel(pcie, PADS_REFCLK_CFG_VALUE, PADS_REFCLK_CFG1); in tegra_pcie_phy_enable()
814 err = tegra_pcie_pll_wait(pcie, 500); in tegra_pcie_phy_enable()
816 dev_err(pcie->dev, "PLL failed to lock: %d\n", err); in tegra_pcie_phy_enable()
821 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
823 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
826 value = pads_readl(pcie, PADS_CTL); in tegra_pcie_phy_enable()
828 pads_writel(pcie, value, PADS_CTL); in tegra_pcie_phy_enable()
833 static int tegra_pcie_enable_controller(struct tegra_pcie *pcie) in tegra_pcie_enable_controller() argument
835 const struct tegra_pcie_soc_data *soc = pcie->soc_data; in tegra_pcie_enable_controller()
841 if (pcie->phy) { in tegra_pcie_enable_controller()
842 value = afi_readl(pcie, AFI_PLLE_CONTROL); in tegra_pcie_enable_controller()
845 afi_writel(pcie, value, AFI_PLLE_CONTROL); in tegra_pcie_enable_controller()
850 afi_writel(pcie, 0, AFI_PEXBIAS_CTRL_0); in tegra_pcie_enable_controller()
853 value = afi_readl(pcie, AFI_PCIE_CONFIG); in tegra_pcie_enable_controller()
855 value |= AFI_PCIE_CONFIG_PCIE_DISABLE_ALL | pcie->xbar_config; in tegra_pcie_enable_controller()
857 list_for_each_entry(port, &pcie->ports, list) in tegra_pcie_enable_controller()
860 afi_writel(pcie, value, AFI_PCIE_CONFIG); in tegra_pcie_enable_controller()
863 value = afi_readl(pcie, AFI_FUSE); in tegra_pcie_enable_controller()
865 afi_writel(pcie, value, AFI_FUSE); in tegra_pcie_enable_controller()
867 value = afi_readl(pcie, AFI_FUSE); in tegra_pcie_enable_controller()
869 afi_writel(pcie, value, AFI_FUSE); in tegra_pcie_enable_controller()
872 if (!pcie->phy) in tegra_pcie_enable_controller()
873 err = tegra_pcie_phy_enable(pcie); in tegra_pcie_enable_controller()
875 err = phy_power_on(pcie->phy); in tegra_pcie_enable_controller()
878 dev_err(pcie->dev, "failed to power on PHY: %d\n", err); in tegra_pcie_enable_controller()
883 reset_control_deassert(pcie->pcie_xrst); in tegra_pcie_enable_controller()
886 value = afi_readl(pcie, AFI_CONFIGURATION); in tegra_pcie_enable_controller()
888 afi_writel(pcie, value, AFI_CONFIGURATION); in tegra_pcie_enable_controller()
897 afi_writel(pcie, value, AFI_AFI_INTR_ENABLE); in tegra_pcie_enable_controller()
898 afi_writel(pcie, 0xffffffff, AFI_SM_INTR_ENABLE); in tegra_pcie_enable_controller()
901 afi_writel(pcie, AFI_INTR_MASK_INT_MASK, AFI_INTR_MASK); in tegra_pcie_enable_controller()
904 afi_writel(pcie, 0, AFI_FPCI_ERROR_MASKS); in tegra_pcie_enable_controller()
909 static void tegra_pcie_power_off(struct tegra_pcie *pcie) in tegra_pcie_power_off() argument
915 err = phy_power_off(pcie->phy); in tegra_pcie_power_off()
917 dev_warn(pcie->dev, "failed to power off PHY: %d\n", err); in tegra_pcie_power_off()
919 reset_control_assert(pcie->pcie_xrst); in tegra_pcie_power_off()
920 reset_control_assert(pcie->afi_rst); in tegra_pcie_power_off()
921 reset_control_assert(pcie->pex_rst); in tegra_pcie_power_off()
925 err = regulator_bulk_disable(pcie->num_supplies, pcie->supplies); in tegra_pcie_power_off()
927 dev_warn(pcie->dev, "failed to disable regulators: %d\n", err); in tegra_pcie_power_off()
930 static int tegra_pcie_power_on(struct tegra_pcie *pcie) in tegra_pcie_power_on() argument
932 const struct tegra_pcie_soc_data *soc = pcie->soc_data; in tegra_pcie_power_on()
935 reset_control_assert(pcie->pcie_xrst); in tegra_pcie_power_on()
936 reset_control_assert(pcie->afi_rst); in tegra_pcie_power_on()
937 reset_control_assert(pcie->pex_rst); in tegra_pcie_power_on()
942 err = regulator_bulk_enable(pcie->num_supplies, pcie->supplies); in tegra_pcie_power_on()
944 dev_err(pcie->dev, "failed to enable regulators: %d\n", err); in tegra_pcie_power_on()
947 pcie->pex_clk, in tegra_pcie_power_on()
948 pcie->pex_rst); in tegra_pcie_power_on()
950 dev_err(pcie->dev, "powerup sequence failed: %d\n", err); in tegra_pcie_power_on()
954 reset_control_deassert(pcie->afi_rst); in tegra_pcie_power_on()
956 err = clk_prepare_enable(pcie->afi_clk); in tegra_pcie_power_on()
958 dev_err(pcie->dev, "failed to enable AFI clock: %d\n", err); in tegra_pcie_power_on()
963 err = clk_prepare_enable(pcie->cml_clk); in tegra_pcie_power_on()
965 dev_err(pcie->dev, "failed to enable CML clock: %d\n", in tegra_pcie_power_on()
971 err = clk_prepare_enable(pcie->pll_e); in tegra_pcie_power_on()
973 dev_err(pcie->dev, "failed to enable PLLE clock: %d\n", err); in tegra_pcie_power_on()
980 static int tegra_pcie_clocks_get(struct tegra_pcie *pcie) in tegra_pcie_clocks_get() argument
982 const struct tegra_pcie_soc_data *soc = pcie->soc_data; in tegra_pcie_clocks_get()
984 pcie->pex_clk = devm_clk_get(pcie->dev, "pex"); in tegra_pcie_clocks_get()
985 if (IS_ERR(pcie->pex_clk)) in tegra_pcie_clocks_get()
986 return PTR_ERR(pcie->pex_clk); in tegra_pcie_clocks_get()
988 pcie->afi_clk = devm_clk_get(pcie->dev, "afi"); in tegra_pcie_clocks_get()
989 if (IS_ERR(pcie->afi_clk)) in tegra_pcie_clocks_get()
990 return PTR_ERR(pcie->afi_clk); in tegra_pcie_clocks_get()
992 pcie->pll_e = devm_clk_get(pcie->dev, "pll_e"); in tegra_pcie_clocks_get()
993 if (IS_ERR(pcie->pll_e)) in tegra_pcie_clocks_get()
994 return PTR_ERR(pcie->pll_e); in tegra_pcie_clocks_get()
997 pcie->cml_clk = devm_clk_get(pcie->dev, "cml"); in tegra_pcie_clocks_get()
998 if (IS_ERR(pcie->cml_clk)) in tegra_pcie_clocks_get()
999 return PTR_ERR(pcie->cml_clk); in tegra_pcie_clocks_get()
1005 static int tegra_pcie_resets_get(struct tegra_pcie *pcie) in tegra_pcie_resets_get() argument
1007 pcie->pex_rst = devm_reset_control_get(pcie->dev, "pex"); in tegra_pcie_resets_get()
1008 if (IS_ERR(pcie->pex_rst)) in tegra_pcie_resets_get()
1009 return PTR_ERR(pcie->pex_rst); in tegra_pcie_resets_get()
1011 pcie->afi_rst = devm_reset_control_get(pcie->dev, "afi"); in tegra_pcie_resets_get()
1012 if (IS_ERR(pcie->afi_rst)) in tegra_pcie_resets_get()
1013 return PTR_ERR(pcie->afi_rst); in tegra_pcie_resets_get()
1015 pcie->pcie_xrst = devm_reset_control_get(pcie->dev, "pcie_x"); in tegra_pcie_resets_get()
1016 if (IS_ERR(pcie->pcie_xrst)) in tegra_pcie_resets_get()
1017 return PTR_ERR(pcie->pcie_xrst); in tegra_pcie_resets_get()
1022 static int tegra_pcie_get_resources(struct tegra_pcie *pcie) in tegra_pcie_get_resources() argument
1024 struct platform_device *pdev = to_platform_device(pcie->dev); in tegra_pcie_get_resources()
1028 err = tegra_pcie_clocks_get(pcie); in tegra_pcie_get_resources()
1034 err = tegra_pcie_resets_get(pcie); in tegra_pcie_get_resources()
1040 pcie->phy = devm_phy_optional_get(pcie->dev, "pcie"); in tegra_pcie_get_resources()
1041 if (IS_ERR(pcie->phy)) { in tegra_pcie_get_resources()
1042 err = PTR_ERR(pcie->phy); in tegra_pcie_get_resources()
1047 err = phy_init(pcie->phy); in tegra_pcie_get_resources()
1053 err = tegra_pcie_power_on(pcie); in tegra_pcie_get_resources()
1060 pcie->pads = devm_ioremap_resource(&pdev->dev, pads); in tegra_pcie_get_resources()
1061 if (IS_ERR(pcie->pads)) { in tegra_pcie_get_resources()
1062 err = PTR_ERR(pcie->pads); in tegra_pcie_get_resources()
1067 pcie->afi = devm_ioremap_resource(&pdev->dev, afi); in tegra_pcie_get_resources()
1068 if (IS_ERR(pcie->afi)) { in tegra_pcie_get_resources()
1069 err = PTR_ERR(pcie->afi); in tegra_pcie_get_resources()
1080 pcie->cs = devm_request_mem_region(pcie->dev, res->start, in tegra_pcie_get_resources()
1082 if (!pcie->cs) { in tegra_pcie_get_resources()
1094 pcie->irq = err; in tegra_pcie_get_resources()
1096 err = request_irq(pcie->irq, tegra_pcie_isr, IRQF_SHARED, "PCIE", pcie); in tegra_pcie_get_resources()
1105 tegra_pcie_power_off(pcie); in tegra_pcie_get_resources()
1109 static int tegra_pcie_put_resources(struct tegra_pcie *pcie) in tegra_pcie_put_resources() argument
1113 if (pcie->irq > 0) in tegra_pcie_put_resources()
1114 free_irq(pcie->irq, pcie); in tegra_pcie_put_resources()
1116 tegra_pcie_power_off(pcie); in tegra_pcie_put_resources()
1118 err = phy_exit(pcie->phy); in tegra_pcie_put_resources()
1120 dev_err(pcie->dev, "failed to teardown PHY: %d\n", err); in tegra_pcie_put_resources()
1158 struct tegra_pcie *pcie = data; in tegra_pcie_msi_irq() local
1159 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_msi_irq()
1163 unsigned long reg = afi_readl(pcie, AFI_MSI_VEC0 + i * 4); in tegra_pcie_msi_irq()
1171 afi_writel(pcie, 1 << offset, AFI_MSI_VEC0 + i * 4); in tegra_pcie_msi_irq()
1178 dev_info(pcie->dev, "unhandled MSI\n"); in tegra_pcie_msi_irq()
1184 dev_info(pcie->dev, "unexpected MSI\n"); in tegra_pcie_msi_irq()
1188 reg = afi_readl(pcie, AFI_MSI_VEC0 + i * 4); in tegra_pcie_msi_irq()
1261 static int tegra_pcie_enable_msi(struct tegra_pcie *pcie) in tegra_pcie_enable_msi() argument
1263 struct platform_device *pdev = to_platform_device(pcie->dev); in tegra_pcie_enable_msi()
1264 const struct tegra_pcie_soc_data *soc = pcie->soc_data; in tegra_pcie_enable_msi()
1265 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_enable_msi()
1272 msi->chip.dev = pcie->dev; in tegra_pcie_enable_msi()
1276 msi->domain = irq_domain_add_linear(pcie->dev->of_node, INT_PCI_MSI_NR, in tegra_pcie_enable_msi()
1292 tegra_msi_irq_chip.name, pcie); in tegra_pcie_enable_msi()
1302 afi_writel(pcie, base >> soc->msi_base_shift, AFI_MSI_FPCI_BAR_ST); in tegra_pcie_enable_msi()
1303 afi_writel(pcie, base, AFI_MSI_AXI_BAR_ST); in tegra_pcie_enable_msi()
1305 afi_writel(pcie, 1, AFI_MSI_BAR_SZ); in tegra_pcie_enable_msi()
1308 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC0); in tegra_pcie_enable_msi()
1309 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC1); in tegra_pcie_enable_msi()
1310 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC2); in tegra_pcie_enable_msi()
1311 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC3); in tegra_pcie_enable_msi()
1312 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC4); in tegra_pcie_enable_msi()
1313 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC5); in tegra_pcie_enable_msi()
1314 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC6); in tegra_pcie_enable_msi()
1315 afi_writel(pcie, 0xffffffff, AFI_MSI_EN_VEC7); in tegra_pcie_enable_msi()
1318 reg = afi_readl(pcie, AFI_INTR_MASK); in tegra_pcie_enable_msi()
1320 afi_writel(pcie, reg, AFI_INTR_MASK); in tegra_pcie_enable_msi()
1329 static int tegra_pcie_disable_msi(struct tegra_pcie *pcie) in tegra_pcie_disable_msi() argument
1331 struct tegra_msi *msi = &pcie->msi; in tegra_pcie_disable_msi()
1336 value = afi_readl(pcie, AFI_INTR_MASK); in tegra_pcie_disable_msi()
1338 afi_writel(pcie, value, AFI_INTR_MASK); in tegra_pcie_disable_msi()
1341 afi_writel(pcie, 0, AFI_MSI_EN_VEC0); in tegra_pcie_disable_msi()
1342 afi_writel(pcie, 0, AFI_MSI_EN_VEC1); in tegra_pcie_disable_msi()
1343 afi_writel(pcie, 0, AFI_MSI_EN_VEC2); in tegra_pcie_disable_msi()
1344 afi_writel(pcie, 0, AFI_MSI_EN_VEC3); in tegra_pcie_disable_msi()
1345 afi_writel(pcie, 0, AFI_MSI_EN_VEC4); in tegra_pcie_disable_msi()
1346 afi_writel(pcie, 0, AFI_MSI_EN_VEC5); in tegra_pcie_disable_msi()
1347 afi_writel(pcie, 0, AFI_MSI_EN_VEC6); in tegra_pcie_disable_msi()
1348 afi_writel(pcie, 0, AFI_MSI_EN_VEC7); in tegra_pcie_disable_msi()
1353 free_irq(msi->irq, pcie); in tegra_pcie_disable_msi()
1366 static int tegra_pcie_get_xbar_config(struct tegra_pcie *pcie, u32 lanes, in tegra_pcie_get_xbar_config() argument
1369 struct device_node *np = pcie->dev->of_node; in tegra_pcie_get_xbar_config()
1374 dev_info(pcie->dev, "4x1, 1x1 configuration\n"); in tegra_pcie_get_xbar_config()
1379 dev_info(pcie->dev, "2x1, 1x1 configuration\n"); in tegra_pcie_get_xbar_config()
1386 dev_info(pcie->dev, "4x1, 2x1 configuration\n"); in tegra_pcie_get_xbar_config()
1391 dev_info(pcie->dev, "2x3 configuration\n"); in tegra_pcie_get_xbar_config()
1396 dev_info(pcie->dev, "4x1, 1x2 configuration\n"); in tegra_pcie_get_xbar_config()
1403 dev_info(pcie->dev, "single-mode configuration\n"); in tegra_pcie_get_xbar_config()
1408 dev_info(pcie->dev, "dual-mode configuration\n"); in tegra_pcie_get_xbar_config()
1446 static int tegra_pcie_get_legacy_regulators(struct tegra_pcie *pcie) in tegra_pcie_get_legacy_regulators() argument
1448 struct device_node *np = pcie->dev->of_node; in tegra_pcie_get_legacy_regulators()
1451 pcie->num_supplies = 3; in tegra_pcie_get_legacy_regulators()
1453 pcie->num_supplies = 2; in tegra_pcie_get_legacy_regulators()
1455 if (pcie->num_supplies == 0) { in tegra_pcie_get_legacy_regulators()
1456 dev_err(pcie->dev, "device %s not supported in legacy mode\n", in tegra_pcie_get_legacy_regulators()
1461 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, in tegra_pcie_get_legacy_regulators()
1462 sizeof(*pcie->supplies), in tegra_pcie_get_legacy_regulators()
1464 if (!pcie->supplies) in tegra_pcie_get_legacy_regulators()
1467 pcie->supplies[0].supply = "pex-clk"; in tegra_pcie_get_legacy_regulators()
1468 pcie->supplies[1].supply = "vdd"; in tegra_pcie_get_legacy_regulators()
1470 if (pcie->num_supplies > 2) in tegra_pcie_get_legacy_regulators()
1471 pcie->supplies[2].supply = "avdd"; in tegra_pcie_get_legacy_regulators()
1473 return devm_regulator_bulk_get(pcie->dev, pcie->num_supplies, in tegra_pcie_get_legacy_regulators()
1474 pcie->supplies); in tegra_pcie_get_legacy_regulators()
1486 static int tegra_pcie_get_regulators(struct tegra_pcie *pcie, u32 lane_mask) in tegra_pcie_get_regulators() argument
1488 struct device_node *np = pcie->dev->of_node; in tegra_pcie_get_regulators()
1492 pcie->num_supplies = 7; in tegra_pcie_get_regulators()
1494 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, in tegra_pcie_get_regulators()
1495 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
1497 if (!pcie->supplies) in tegra_pcie_get_regulators()
1500 pcie->supplies[i++].supply = "avddio-pex"; in tegra_pcie_get_regulators()
1501 pcie->supplies[i++].supply = "dvddio-pex"; in tegra_pcie_get_regulators()
1502 pcie->supplies[i++].supply = "avdd-pex-pll"; in tegra_pcie_get_regulators()
1503 pcie->supplies[i++].supply = "hvdd-pex"; in tegra_pcie_get_regulators()
1504 pcie->supplies[i++].supply = "hvdd-pex-pll-e"; in tegra_pcie_get_regulators()
1505 pcie->supplies[i++].supply = "vddio-pex-ctl"; in tegra_pcie_get_regulators()
1506 pcie->supplies[i++].supply = "avdd-pll-erefe"; in tegra_pcie_get_regulators()
1518 pcie->num_supplies = 4 + (need_pexa ? 2 : 0) + in tegra_pcie_get_regulators()
1521 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, in tegra_pcie_get_regulators()
1522 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
1524 if (!pcie->supplies) in tegra_pcie_get_regulators()
1527 pcie->supplies[i++].supply = "avdd-pex-pll"; in tegra_pcie_get_regulators()
1528 pcie->supplies[i++].supply = "hvdd-pex"; in tegra_pcie_get_regulators()
1529 pcie->supplies[i++].supply = "vddio-pex-ctl"; in tegra_pcie_get_regulators()
1530 pcie->supplies[i++].supply = "avdd-plle"; in tegra_pcie_get_regulators()
1533 pcie->supplies[i++].supply = "avdd-pexa"; in tegra_pcie_get_regulators()
1534 pcie->supplies[i++].supply = "vdd-pexa"; in tegra_pcie_get_regulators()
1538 pcie->supplies[i++].supply = "avdd-pexb"; in tegra_pcie_get_regulators()
1539 pcie->supplies[i++].supply = "vdd-pexb"; in tegra_pcie_get_regulators()
1542 pcie->num_supplies = 5; in tegra_pcie_get_regulators()
1544 pcie->supplies = devm_kcalloc(pcie->dev, pcie->num_supplies, in tegra_pcie_get_regulators()
1545 sizeof(*pcie->supplies), in tegra_pcie_get_regulators()
1547 if (!pcie->supplies) in tegra_pcie_get_regulators()
1550 pcie->supplies[0].supply = "avdd-pex"; in tegra_pcie_get_regulators()
1551 pcie->supplies[1].supply = "vdd-pex"; in tegra_pcie_get_regulators()
1552 pcie->supplies[2].supply = "avdd-pex-pll"; in tegra_pcie_get_regulators()
1553 pcie->supplies[3].supply = "avdd-plle"; in tegra_pcie_get_regulators()
1554 pcie->supplies[4].supply = "vddio-pex-clk"; in tegra_pcie_get_regulators()
1557 if (of_regulator_bulk_available(pcie->dev->of_node, pcie->supplies, in tegra_pcie_get_regulators()
1558 pcie->num_supplies)) in tegra_pcie_get_regulators()
1559 return devm_regulator_bulk_get(pcie->dev, pcie->num_supplies, in tegra_pcie_get_regulators()
1560 pcie->supplies); in tegra_pcie_get_regulators()
1567 dev_info(pcie->dev, "using legacy DT binding for power supplies\n"); in tegra_pcie_get_regulators()
1569 devm_kfree(pcie->dev, pcie->supplies); in tegra_pcie_get_regulators()
1570 pcie->num_supplies = 0; in tegra_pcie_get_regulators()
1572 return tegra_pcie_get_legacy_regulators(pcie); in tegra_pcie_get_regulators()
1575 static int tegra_pcie_parse_dt(struct tegra_pcie *pcie) in tegra_pcie_parse_dt() argument
1577 const struct tegra_pcie_soc_data *soc = pcie->soc_data; in tegra_pcie_parse_dt()
1578 struct device_node *np = pcie->dev->of_node, *port; in tegra_pcie_parse_dt()
1586 memset(&pcie->all, 0, sizeof(pcie->all)); in tegra_pcie_parse_dt()
1587 pcie->all.flags = IORESOURCE_MEM; in tegra_pcie_parse_dt()
1588 pcie->all.name = np->full_name; in tegra_pcie_parse_dt()
1589 pcie->all.start = ~0; in tegra_pcie_parse_dt()
1590 pcie->all.end = 0; in tegra_pcie_parse_dt()
1593 dev_err(pcie->dev, "missing \"ranges\" property\n"); in tegra_pcie_parse_dt()
1604 memcpy(&pcie->pio, &res, sizeof(res)); in tegra_pcie_parse_dt()
1605 pcie->pio.name = np->full_name; in tegra_pcie_parse_dt()
1615 pcie->io.start = range.cpu_addr; in tegra_pcie_parse_dt()
1616 pcie->io.end = range.cpu_addr + range.size - 1; in tegra_pcie_parse_dt()
1617 pcie->io.flags = IORESOURCE_MEM; in tegra_pcie_parse_dt()
1618 pcie->io.name = "I/O"; in tegra_pcie_parse_dt()
1620 memcpy(&res, &pcie->io, sizeof(res)); in tegra_pcie_parse_dt()
1625 memcpy(&pcie->prefetch, &res, sizeof(res)); in tegra_pcie_parse_dt()
1626 pcie->prefetch.name = "prefetchable"; in tegra_pcie_parse_dt()
1628 memcpy(&pcie->mem, &res, sizeof(res)); in tegra_pcie_parse_dt()
1629 pcie->mem.name = "non-prefetchable"; in tegra_pcie_parse_dt()
1634 if (res.start <= pcie->all.start) in tegra_pcie_parse_dt()
1635 pcie->all.start = res.start; in tegra_pcie_parse_dt()
1637 if (res.end >= pcie->all.end) in tegra_pcie_parse_dt()
1638 pcie->all.end = res.end; in tegra_pcie_parse_dt()
1641 err = devm_request_resource(pcie->dev, &iomem_resource, &pcie->all); in tegra_pcie_parse_dt()
1645 err = of_pci_parse_bus_range(np, &pcie->busn); in tegra_pcie_parse_dt()
1647 dev_err(pcie->dev, "failed to parse ranges property: %d\n", in tegra_pcie_parse_dt()
1649 pcie->busn.name = np->name; in tegra_pcie_parse_dt()
1650 pcie->busn.start = 0; in tegra_pcie_parse_dt()
1651 pcie->busn.end = 0xff; in tegra_pcie_parse_dt()
1652 pcie->busn.flags = IORESOURCE_BUS; in tegra_pcie_parse_dt()
1663 dev_err(pcie->dev, "failed to parse address: %d\n", in tegra_pcie_parse_dt()
1671 dev_err(pcie->dev, "invalid port number: %d\n", index); in tegra_pcie_parse_dt()
1679 dev_err(pcie->dev, "failed to parse # of lanes: %d\n", in tegra_pcie_parse_dt()
1685 dev_err(pcie->dev, "invalid # of lanes: %u\n", value); in tegra_pcie_parse_dt()
1699 rp = devm_kzalloc(pcie->dev, sizeof(*rp), GFP_KERNEL); in tegra_pcie_parse_dt()
1705 dev_err(pcie->dev, "failed to parse address: %d\n", in tegra_pcie_parse_dt()
1713 rp->pcie = pcie; in tegra_pcie_parse_dt()
1715 rp->base = devm_ioremap_resource(pcie->dev, &rp->regs); in tegra_pcie_parse_dt()
1719 list_add_tail(&rp->list, &pcie->ports); in tegra_pcie_parse_dt()
1722 err = tegra_pcie_get_xbar_config(pcie, lanes, &pcie->xbar_config); in tegra_pcie_parse_dt()
1724 dev_err(pcie->dev, "invalid lane configuration\n"); in tegra_pcie_parse_dt()
1728 err = tegra_pcie_get_regulators(pcie, mask); in tegra_pcie_parse_dt()
1765 dev_err(port->pcie->dev, "link %u down, retrying\n", in tegra_pcie_port_check_link()
1788 static int tegra_pcie_enable(struct tegra_pcie *pcie) in tegra_pcie_enable() argument
1793 list_for_each_entry_safe(port, tmp, &pcie->ports, list) { in tegra_pcie_enable()
1794 dev_info(pcie->dev, "probing port %u, using %u lanes\n", in tegra_pcie_enable()
1802 dev_info(pcie->dev, "link %u down, ignoring\n", port->index); in tegra_pcie_enable()
1811 hw.msi_ctrl = &pcie->msi.chip; in tegra_pcie_enable()
1815 hw.private_data = (void **)&pcie; in tegra_pcie_enable()
1820 pci_common_init_dev(pcie->dev, &hw); in tegra_pcie_enable()
1871 struct tegra_pcie *pcie = s->private; in tegra_pcie_ports_seq_start() local
1873 if (list_empty(&pcie->ports)) in tegra_pcie_ports_seq_start()
1878 return seq_list_start(&pcie->ports, *pos); in tegra_pcie_ports_seq_start()
1883 struct tegra_pcie *pcie = s->private; in tegra_pcie_ports_seq_next() local
1885 return seq_list_next(v, &pcie->ports, pos); in tegra_pcie_ports_seq_next()
1935 struct tegra_pcie *pcie = inode->i_private; in tegra_pcie_ports_open() local
1944 s->private = pcie; in tegra_pcie_ports_open()
1957 static int tegra_pcie_debugfs_init(struct tegra_pcie *pcie) in tegra_pcie_debugfs_init() argument
1961 pcie->debugfs = debugfs_create_dir("pcie", NULL); in tegra_pcie_debugfs_init()
1962 if (!pcie->debugfs) in tegra_pcie_debugfs_init()
1965 file = debugfs_create_file("ports", S_IFREG | S_IRUGO, pcie->debugfs, in tegra_pcie_debugfs_init()
1966 pcie, &tegra_pcie_ports_ops); in tegra_pcie_debugfs_init()
1973 debugfs_remove_recursive(pcie->debugfs); in tegra_pcie_debugfs_init()
1974 pcie->debugfs = NULL; in tegra_pcie_debugfs_init()
1981 struct tegra_pcie *pcie; in tegra_pcie_probe() local
1988 pcie = devm_kzalloc(&pdev->dev, sizeof(*pcie), GFP_KERNEL); in tegra_pcie_probe()
1989 if (!pcie) in tegra_pcie_probe()
1992 INIT_LIST_HEAD(&pcie->buses); in tegra_pcie_probe()
1993 INIT_LIST_HEAD(&pcie->ports); in tegra_pcie_probe()
1994 pcie->soc_data = match->data; in tegra_pcie_probe()
1995 pcie->dev = &pdev->dev; in tegra_pcie_probe()
1997 err = tegra_pcie_parse_dt(pcie); in tegra_pcie_probe()
2003 err = tegra_pcie_get_resources(pcie); in tegra_pcie_probe()
2009 err = tegra_pcie_enable_controller(pcie); in tegra_pcie_probe()
2014 tegra_pcie_setup_translations(pcie); in tegra_pcie_probe()
2017 err = tegra_pcie_enable_msi(pcie); in tegra_pcie_probe()
2026 err = tegra_pcie_enable(pcie); in tegra_pcie_probe()
2033 err = tegra_pcie_debugfs_init(pcie); in tegra_pcie_probe()
2039 platform_set_drvdata(pdev, pcie); in tegra_pcie_probe()
2044 tegra_pcie_disable_msi(pcie); in tegra_pcie_probe()
2046 tegra_pcie_put_resources(pcie); in tegra_pcie_probe()