Lines Matching +full:pci +full:- +full:rcar +full:- +full:gen2
1 // SPDX-License-Identifier: GPL-2.0
3 * PCIe driver for Renesas R-Car SoCs
4 * Copyright (C) 2014-2020 Renesas Electronics Europe Ltd
7 * arch/sh/drivers/pci/pcie-sh7786.c
8 * arch/sh/drivers/pci/ops-sh7786.c
9 * Copyright (C) 2009 - 2011 Paul Mundt
16 #include <linux/clk-provider.h>
28 #include <linux/pci.h>
33 #include "pcie-rcar.h"
64 ret = -EINVAL; in rcar_pcie_wakeup()
104 " .arch armv7-a\n" \
126 : "+r"(error):"r"(val), "r"(pcie->base + reg) : "memory"); in rcar_pci_write_reg_workaround()
140 : "+r"(error), "=r"(*val) : "r"(pcie->base + reg) : "memory"); in rcar_pci_read_reg_workaround()
150 /* Serialization is provided by 'pci_lock' in drivers/pci/access.c */
155 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_config_access()
160 ret = rcar_pcie_wakeup(pcie->dev, pcie->base); in rcar_pcie_config_access()
172 * While each channel has its own memory-mapped extended config in rcar_pcie_config_access()
180 * the same channel <-> device access works for any PCI_SLOT() in rcar_pcie_config_access()
182 * space to devfn 0 in order to enable self-enumeration. In this in rcar_pcie_config_access()
202 rcar_pci_write_reg(pcie, PCIE_CONF_BUS(bus->number) | in rcar_pcie_config_access()
206 if (pci_is_root_bus(bus->parent)) in rcar_pcie_config_access()
234 struct rcar_pcie_host *host = bus->sysdata; in rcar_pcie_read_conf()
247 dev_dbg(&bus->dev, "pcie-config-read: bus=%3d devfn=0x%04x where=0x%04x size=%d val=0x%08x\n", in rcar_pcie_read_conf()
248 bus->number, devfn, where, size, *val); in rcar_pcie_read_conf()
253 /* Serialization is provided by 'pci_lock' in drivers/pci/access.c */
257 struct rcar_pcie_host *host = bus->sysdata; in rcar_pcie_write_conf()
267 dev_dbg(&bus->dev, "pcie-config-write: bus=%3d devfn=0x%04x where=0x%04x size=%d val=0x%08x\n", in rcar_pcie_write_conf()
268 bus->number, devfn, where, size, val); in rcar_pcie_write_conf()
294 struct device *dev = pcie->dev; in rcar_pcie_force_speedup()
324 while (timeout--) { in rcar_pcie_force_speedup()
348 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_hw_enable()
357 /* Setup PCI resources */ in rcar_pcie_hw_enable()
358 resource_list_for_each_entry(win, &bridge->windows) { in rcar_pcie_hw_enable()
359 struct resource *res = win->res; in rcar_pcie_hw_enable()
361 if (!res->flags) in rcar_pcie_hw_enable()
382 bridge->sysdata = host; in rcar_pcie_enable()
383 bridge->ops = &rcar_pcie_ops; in rcar_pcie_enable()
390 struct device *dev = pcie->dev; in phy_wait_for_ack()
393 while (timeout--) { in phy_wait_for_ack()
402 return -ETIMEDOUT; in phy_wait_for_ack()
485 /* Finish initialization - establish a PCI Express link */ in rcar_pcie_hw_init()
503 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_phy_init_h1()
528 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_phy_init_gen2()
531 * These settings come from the R-Car Series, 2nd Generation User's in rcar_pcie_phy_init_gen2()
552 err = phy_init(host->phy); in rcar_pcie_phy_init_gen3()
556 err = phy_power_on(host->phy); in rcar_pcie_phy_init_gen3()
558 phy_exit(host->phy); in rcar_pcie_phy_init_gen3()
566 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_msi_irq()
567 struct rcar_msi *msi = &host->msi; in rcar_pcie_msi_irq()
568 struct device *dev = pcie->dev; in rcar_pcie_msi_irq()
573 /* MSI & INTx share an interrupt - we only handle MSI here */ in rcar_pcie_msi_irq()
581 ret = generic_handle_domain_irq(msi->domain->parent, index); in rcar_pcie_msi_irq()
622 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_msi_irq_ack()
625 rcar_pci_write_reg(pcie, BIT(d->hwirq), PCIEMSIFR); in rcar_msi_irq_ack()
631 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_msi_irq_mask()
635 spin_lock_irqsave(&msi->mask_lock, flags); in rcar_msi_irq_mask()
637 value &= ~BIT(d->hwirq); in rcar_msi_irq_mask()
639 spin_unlock_irqrestore(&msi->mask_lock, flags); in rcar_msi_irq_mask()
645 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_msi_irq_unmask()
649 spin_lock_irqsave(&msi->mask_lock, flags); in rcar_msi_irq_unmask()
651 value |= BIT(d->hwirq); in rcar_msi_irq_unmask()
653 spin_unlock_irqrestore(&msi->mask_lock, flags); in rcar_msi_irq_unmask()
658 return -EINVAL; in rcar_msi_set_affinity()
664 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_compose_msi_msg()
666 msg->address_lo = rcar_pci_read_reg(pcie, PCIEMSIALR) & ~MSIFE; in rcar_compose_msi_msg()
667 msg->address_hi = rcar_pci_read_reg(pcie, PCIEMSIAUR); in rcar_compose_msi_msg()
668 msg->data = data->hwirq; in rcar_compose_msi_msg()
672 .name = "R-Car MSI",
683 struct rcar_msi *msi = domain->host_data; in rcar_msi_domain_alloc()
687 mutex_lock(&msi->map_lock); in rcar_msi_domain_alloc()
689 hwirq = bitmap_find_free_region(msi->used, INT_PCI_MSI_NR, order_base_2(nr_irqs)); in rcar_msi_domain_alloc()
691 mutex_unlock(&msi->map_lock); in rcar_msi_domain_alloc()
694 return -ENOSPC; in rcar_msi_domain_alloc()
698 &rcar_msi_bottom_chip, domain->host_data, in rcar_msi_domain_alloc()
708 struct rcar_msi *msi = domain->host_data; in rcar_msi_domain_free()
710 mutex_lock(&msi->map_lock); in rcar_msi_domain_free()
712 bitmap_release_region(msi->used, d->hwirq, order_base_2(nr_irqs)); in rcar_msi_domain_free()
714 mutex_unlock(&msi->map_lock); in rcar_msi_domain_free()
730 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_allocate_domains()
731 struct fwnode_handle *fwnode = dev_fwnode(pcie->dev); in rcar_allocate_domains()
737 dev_err(pcie->dev, "failed to create IRQ domain\n"); in rcar_allocate_domains()
738 return -ENOMEM; in rcar_allocate_domains()
742 msi->domain = pci_msi_create_irq_domain(fwnode, &rcar_msi_info, parent); in rcar_allocate_domains()
743 if (!msi->domain) { in rcar_allocate_domains()
744 dev_err(pcie->dev, "failed to create MSI domain\n"); in rcar_allocate_domains()
746 return -ENOMEM; in rcar_allocate_domains()
754 struct irq_domain *parent = msi->domain->parent; in rcar_free_domains()
756 irq_domain_remove(msi->domain); in rcar_free_domains()
762 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_enable_msi()
763 struct device *dev = pcie->dev; in rcar_pcie_enable_msi()
764 struct rcar_msi *msi = &host->msi; in rcar_pcie_enable_msi()
768 mutex_init(&msi->map_lock); in rcar_pcie_enable_msi()
769 spin_lock_init(&msi->mask_lock); in rcar_pcie_enable_msi()
771 err = of_address_to_resource(dev->of_node, 0, &res); in rcar_pcie_enable_msi()
779 /* Two irqs are for MSI, but they are also used for non-MSI irqs */ in rcar_pcie_enable_msi()
780 err = devm_request_irq(dev, msi->irq1, rcar_pcie_msi_irq, in rcar_pcie_enable_msi()
788 err = devm_request_irq(dev, msi->irq2, rcar_pcie_msi_irq, in rcar_pcie_enable_msi()
801 * is guaranteed to be in the low 32bit range on any R-Car HW. in rcar_pcie_enable_msi()
815 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_teardown_msi()
823 rcar_free_domains(&host->msi); in rcar_pcie_teardown_msi()
828 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_get_resources()
829 struct device *dev = pcie->dev; in rcar_pcie_get_resources()
833 host->phy = devm_phy_optional_get(dev, "pcie"); in rcar_pcie_get_resources()
834 if (IS_ERR(host->phy)) in rcar_pcie_get_resources()
835 return PTR_ERR(host->phy); in rcar_pcie_get_resources()
837 err = of_address_to_resource(dev->of_node, 0, &res); in rcar_pcie_get_resources()
841 pcie->base = devm_ioremap_resource(dev, &res); in rcar_pcie_get_resources()
842 if (IS_ERR(pcie->base)) in rcar_pcie_get_resources()
843 return PTR_ERR(pcie->base); in rcar_pcie_get_resources()
845 host->bus_clk = devm_clk_get(dev, "pcie_bus"); in rcar_pcie_get_resources()
846 if (IS_ERR(host->bus_clk)) { in rcar_pcie_get_resources()
848 return PTR_ERR(host->bus_clk); in rcar_pcie_get_resources()
851 i = irq_of_parse_and_map(dev->of_node, 0); in rcar_pcie_get_resources()
854 err = -ENOENT; in rcar_pcie_get_resources()
857 host->msi.irq1 = i; in rcar_pcie_get_resources()
859 i = irq_of_parse_and_map(dev->of_node, 1); in rcar_pcie_get_resources()
862 err = -ENOENT; in rcar_pcie_get_resources()
865 host->msi.irq2 = i; in rcar_pcie_get_resources()
870 irq_dispose_mapping(host->msi.irq1); in rcar_pcie_get_resources()
879 u64 restype = entry->res->flags; in rcar_pcie_inbound_ranges()
880 u64 cpu_addr = entry->res->start; in rcar_pcie_inbound_ranges()
881 u64 cpu_end = entry->res->end; in rcar_pcie_inbound_ranges()
882 u64 pci_addr = entry->res->start - entry->offset; in rcar_pcie_inbound_ranges()
885 u64 size = resource_size(entry->res); in rcar_pcie_inbound_ranges()
892 if (idx >= MAX_NR_INBOUND_MAPS - 1) { in rcar_pcie_inbound_ranges()
893 dev_err(pcie->dev, "Failed to map inbound regions!\n"); in rcar_pcie_inbound_ranges()
894 return -EINVAL; in rcar_pcie_inbound_ranges()
910 mask = roundup_pow_of_two(size) - 1; in rcar_pcie_inbound_ranges()
931 resource_list_for_each_entry(entry, &bridge->dma_ranges) { in rcar_pcie_parse_map_dma_ranges()
932 err = rcar_pcie_inbound_ranges(&host->pcie, entry, &index); in rcar_pcie_parse_map_dma_ranges()
941 { .compatible = "renesas,pcie-r8a7779",
943 { .compatible = "renesas,pcie-r8a7790",
945 { .compatible = "renesas,pcie-r8a7791",
947 { .compatible = "renesas,pcie-rcar-gen2",
949 { .compatible = "renesas,pcie-r8a7795",
951 { .compatible = "renesas,pcie-rcar-gen3",
958 struct device *dev = &pdev->dev; in rcar_pcie_probe()
967 return -ENOMEM; in rcar_pcie_probe()
970 pcie = &host->pcie; in rcar_pcie_probe()
971 pcie->dev = dev; in rcar_pcie_probe()
974 pm_runtime_enable(pcie->dev); in rcar_pcie_probe()
975 err = pm_runtime_get_sync(pcie->dev); in rcar_pcie_probe()
977 dev_err(pcie->dev, "pm_runtime_get_sync failed\n"); in rcar_pcie_probe()
987 err = clk_prepare_enable(host->bus_clk); in rcar_pcie_probe()
997 host->phy_init_fn = of_device_get_match_data(dev); in rcar_pcie_probe()
998 err = host->phy_init_fn(host); in rcar_pcie_probe()
1007 err = -ENODEV; in rcar_pcie_probe()
1035 if (host->phy) { in rcar_pcie_probe()
1036 phy_power_off(host->phy); in rcar_pcie_probe()
1037 phy_exit(host->phy); in rcar_pcie_probe()
1041 clk_disable_unprepare(host->bus_clk); in rcar_pcie_probe()
1044 irq_dispose_mapping(host->msi.irq2); in rcar_pcie_probe()
1045 irq_dispose_mapping(host->msi.irq1); in rcar_pcie_probe()
1057 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_resume()
1066 err = host->phy_init_fn(host); in rcar_pcie_resume()
1080 of_address_to_resource(dev->of_node, 0, &res); in rcar_pcie_resume()
1084 bitmap_to_arr32(&val, host->msi.used, INT_PCI_MSI_NR); in rcar_pcie_resume()
1096 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_resume_noirq()
1102 /* Re-establish the PCIe link */ in rcar_pcie_resume_noirq()
1115 .name = "rcar-pcie",
1131 { .compatible = "renesas,pcie-r8a7779" },
1132 { .compatible = "renesas,pcie-r8a7790" },
1133 { .compatible = "renesas,pcie-r8a7791" },
1134 { .compatible = "renesas,pcie-rcar-gen2" },