Lines Matching +full:rcar +full:- +full:gen2 +full:- +full:can
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>
33 #include "pcie-rcar.h"
53 * Static copy of PCIe device pointer, so we can check whether the
79 ret = -EINVAL; in rcar_pcie_wakeup()
89 * which it can return to L0s/L0 on its own. in rcar_pcie_wakeup()
119 " .arch armv7-a\n" \
141 : "+r"(error):"r"(val), "r"(pcie->base + reg) : "memory"); in rcar_pci_write_reg_workaround()
155 : "+r"(error), "=r"(*val) : "r"(pcie->base + reg) : "memory"); in rcar_pci_read_reg_workaround()
170 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_config_access()
175 ret = rcar_pcie_wakeup(pcie->dev, pcie->base); in rcar_pcie_config_access()
187 * While each channel has its own memory-mapped extended config in rcar_pcie_config_access()
195 * the same channel <-> device access works for any PCI_SLOT() in rcar_pcie_config_access()
197 * space to devfn 0 in order to enable self-enumeration. In this in rcar_pcie_config_access()
217 rcar_pci_write_reg(pcie, PCIE_CONF_BUS(bus->number) | in rcar_pcie_config_access()
221 if (pci_is_root_bus(bus->parent)) in rcar_pcie_config_access()
249 struct rcar_pcie_host *host = bus->sysdata; in rcar_pcie_read_conf()
262 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()
263 bus->number, devfn, where, size, *val); in rcar_pcie_read_conf()
272 struct rcar_pcie_host *host = bus->sysdata; in rcar_pcie_write_conf()
282 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()
283 bus->number, devfn, where, size, val); in rcar_pcie_write_conf()
309 struct device *dev = pcie->dev; in rcar_pcie_force_speedup()
339 while (timeout--) { in rcar_pcie_force_speedup()
363 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_hw_enable()
373 resource_list_for_each_entry(win, &bridge->windows) { in rcar_pcie_hw_enable()
374 struct resource *res = win->res; in rcar_pcie_hw_enable()
376 if (!res->flags) in rcar_pcie_hw_enable()
397 bridge->sysdata = host; in rcar_pcie_enable()
398 bridge->ops = &rcar_pcie_ops; in rcar_pcie_enable()
405 struct device *dev = pcie->dev; in phy_wait_for_ack()
408 while (timeout--) { in phy_wait_for_ack()
417 return -ETIMEDOUT; in phy_wait_for_ack()
500 /* Finish initialization - establish a PCI Express link */ in rcar_pcie_hw_init()
518 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_phy_init_h1()
543 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_phy_init_gen2()
546 * These settings come from the R-Car Series, 2nd Generation User's in rcar_pcie_phy_init_gen2()
567 err = phy_init(host->phy); in rcar_pcie_phy_init_gen3()
571 err = phy_power_on(host->phy); in rcar_pcie_phy_init_gen3()
573 phy_exit(host->phy); in rcar_pcie_phy_init_gen3()
581 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_msi_irq()
582 struct rcar_msi *msi = &host->msi; in rcar_pcie_msi_irq()
583 struct device *dev = pcie->dev; in rcar_pcie_msi_irq()
588 /* MSI & INTx share an interrupt - we only handle MSI here */ in rcar_pcie_msi_irq()
596 ret = generic_handle_domain_irq(msi->domain->parent, index); in rcar_pcie_msi_irq()
637 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_msi_irq_ack()
640 rcar_pci_write_reg(pcie, BIT(d->hwirq), PCIEMSIFR); in rcar_msi_irq_ack()
646 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_msi_irq_mask()
650 spin_lock_irqsave(&msi->mask_lock, flags); in rcar_msi_irq_mask()
652 value &= ~BIT(d->hwirq); in rcar_msi_irq_mask()
654 spin_unlock_irqrestore(&msi->mask_lock, flags); in rcar_msi_irq_mask()
660 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_msi_irq_unmask()
664 spin_lock_irqsave(&msi->mask_lock, flags); in rcar_msi_irq_unmask()
666 value |= BIT(d->hwirq); in rcar_msi_irq_unmask()
668 spin_unlock_irqrestore(&msi->mask_lock, flags); in rcar_msi_irq_unmask()
673 return -EINVAL; in rcar_msi_set_affinity()
679 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_compose_msi_msg()
681 msg->address_lo = rcar_pci_read_reg(pcie, PCIEMSIALR) & ~MSIFE; in rcar_compose_msi_msg()
682 msg->address_hi = rcar_pci_read_reg(pcie, PCIEMSIAUR); in rcar_compose_msi_msg()
683 msg->data = data->hwirq; in rcar_compose_msi_msg()
687 .name = "Rcar MSI",
698 struct rcar_msi *msi = domain->host_data; in rcar_msi_domain_alloc()
702 mutex_lock(&msi->map_lock); in rcar_msi_domain_alloc()
704 hwirq = bitmap_find_free_region(msi->used, INT_PCI_MSI_NR, order_base_2(nr_irqs)); in rcar_msi_domain_alloc()
706 mutex_unlock(&msi->map_lock); in rcar_msi_domain_alloc()
709 return -ENOSPC; in rcar_msi_domain_alloc()
713 &rcar_msi_bottom_chip, domain->host_data, in rcar_msi_domain_alloc()
723 struct rcar_msi *msi = domain->host_data; in rcar_msi_domain_free()
725 mutex_lock(&msi->map_lock); in rcar_msi_domain_free()
727 bitmap_release_region(msi->used, d->hwirq, order_base_2(nr_irqs)); in rcar_msi_domain_free()
729 mutex_unlock(&msi->map_lock); in rcar_msi_domain_free()
745 struct rcar_pcie *pcie = &msi_to_host(msi)->pcie; in rcar_allocate_domains()
746 struct fwnode_handle *fwnode = dev_fwnode(pcie->dev); in rcar_allocate_domains()
752 dev_err(pcie->dev, "failed to create IRQ domain\n"); in rcar_allocate_domains()
753 return -ENOMEM; in rcar_allocate_domains()
757 msi->domain = pci_msi_create_irq_domain(fwnode, &rcar_msi_info, parent); in rcar_allocate_domains()
758 if (!msi->domain) { in rcar_allocate_domains()
759 dev_err(pcie->dev, "failed to create MSI domain\n"); in rcar_allocate_domains()
761 return -ENOMEM; in rcar_allocate_domains()
769 struct irq_domain *parent = msi->domain->parent; in rcar_free_domains()
771 irq_domain_remove(msi->domain); in rcar_free_domains()
777 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_enable_msi()
778 struct device *dev = pcie->dev; in rcar_pcie_enable_msi()
779 struct rcar_msi *msi = &host->msi; in rcar_pcie_enable_msi()
783 mutex_init(&msi->map_lock); in rcar_pcie_enable_msi()
784 spin_lock_init(&msi->mask_lock); in rcar_pcie_enable_msi()
786 err = of_address_to_resource(dev->of_node, 0, &res); in rcar_pcie_enable_msi()
794 /* Two irqs are for MSI, but they are also used for non-MSI irqs */ in rcar_pcie_enable_msi()
795 err = devm_request_irq(dev, msi->irq1, rcar_pcie_msi_irq, in rcar_pcie_enable_msi()
803 err = devm_request_irq(dev, msi->irq2, rcar_pcie_msi_irq, in rcar_pcie_enable_msi()
816 * is guaranteed to be in the low 32bit range on any RCar HW. in rcar_pcie_enable_msi()
830 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_teardown_msi()
838 rcar_free_domains(&host->msi); in rcar_pcie_teardown_msi()
843 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_get_resources()
844 struct device *dev = pcie->dev; in rcar_pcie_get_resources()
848 host->phy = devm_phy_optional_get(dev, "pcie"); in rcar_pcie_get_resources()
849 if (IS_ERR(host->phy)) in rcar_pcie_get_resources()
850 return PTR_ERR(host->phy); in rcar_pcie_get_resources()
852 err = of_address_to_resource(dev->of_node, 0, &res); in rcar_pcie_get_resources()
856 pcie->base = devm_ioremap_resource(dev, &res); in rcar_pcie_get_resources()
857 if (IS_ERR(pcie->base)) in rcar_pcie_get_resources()
858 return PTR_ERR(pcie->base); in rcar_pcie_get_resources()
860 host->bus_clk = devm_clk_get(dev, "pcie_bus"); in rcar_pcie_get_resources()
861 if (IS_ERR(host->bus_clk)) { in rcar_pcie_get_resources()
863 return PTR_ERR(host->bus_clk); in rcar_pcie_get_resources()
866 i = irq_of_parse_and_map(dev->of_node, 0); in rcar_pcie_get_resources()
869 err = -ENOENT; in rcar_pcie_get_resources()
872 host->msi.irq1 = i; in rcar_pcie_get_resources()
874 i = irq_of_parse_and_map(dev->of_node, 1); in rcar_pcie_get_resources()
877 err = -ENOENT; in rcar_pcie_get_resources()
880 host->msi.irq2 = i; in rcar_pcie_get_resources()
884 pcie_base = pcie->base; in rcar_pcie_get_resources()
885 pcie_dev = pcie->dev; in rcar_pcie_get_resources()
891 irq_dispose_mapping(host->msi.irq1); in rcar_pcie_get_resources()
900 u64 restype = entry->res->flags; in rcar_pcie_inbound_ranges()
901 u64 cpu_addr = entry->res->start; in rcar_pcie_inbound_ranges()
902 u64 cpu_end = entry->res->end; in rcar_pcie_inbound_ranges()
903 u64 pci_addr = entry->res->start - entry->offset; in rcar_pcie_inbound_ranges()
906 u64 size = resource_size(entry->res); in rcar_pcie_inbound_ranges()
913 if (idx >= MAX_NR_INBOUND_MAPS - 1) { in rcar_pcie_inbound_ranges()
914 dev_err(pcie->dev, "Failed to map inbound regions!\n"); in rcar_pcie_inbound_ranges()
915 return -EINVAL; in rcar_pcie_inbound_ranges()
931 mask = roundup_pow_of_two(size) - 1; in rcar_pcie_inbound_ranges()
952 resource_list_for_each_entry(entry, &bridge->dma_ranges) { in rcar_pcie_parse_map_dma_ranges()
953 err = rcar_pcie_inbound_ranges(&host->pcie, entry, &index); in rcar_pcie_parse_map_dma_ranges()
962 { .compatible = "renesas,pcie-r8a7779",
964 { .compatible = "renesas,pcie-r8a7790",
966 { .compatible = "renesas,pcie-r8a7791",
968 { .compatible = "renesas,pcie-rcar-gen2",
970 { .compatible = "renesas,pcie-r8a7795",
972 { .compatible = "renesas,pcie-rcar-gen3",
979 struct device *dev = &pdev->dev; in rcar_pcie_probe()
988 return -ENOMEM; in rcar_pcie_probe()
991 pcie = &host->pcie; in rcar_pcie_probe()
992 pcie->dev = dev; in rcar_pcie_probe()
995 pm_runtime_enable(pcie->dev); in rcar_pcie_probe()
996 err = pm_runtime_get_sync(pcie->dev); in rcar_pcie_probe()
998 dev_err(pcie->dev, "pm_runtime_get_sync failed\n"); in rcar_pcie_probe()
1008 err = clk_prepare_enable(host->bus_clk); in rcar_pcie_probe()
1018 host->phy_init_fn = of_device_get_match_data(dev); in rcar_pcie_probe()
1019 err = host->phy_init_fn(host); in rcar_pcie_probe()
1028 err = -ENODEV; in rcar_pcie_probe()
1056 if (host->phy) { in rcar_pcie_probe()
1057 phy_power_off(host->phy); in rcar_pcie_probe()
1058 phy_exit(host->phy); in rcar_pcie_probe()
1062 clk_disable_unprepare(host->bus_clk); in rcar_pcie_probe()
1065 irq_dispose_mapping(host->msi.irq2); in rcar_pcie_probe()
1066 irq_dispose_mapping(host->msi.irq1); in rcar_pcie_probe()
1078 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_resume()
1087 err = host->phy_init_fn(host); in rcar_pcie_resume()
1101 of_address_to_resource(dev->of_node, 0, &res); in rcar_pcie_resume()
1105 bitmap_to_arr32(&val, host->msi.used, INT_PCI_MSI_NR); in rcar_pcie_resume()
1117 struct rcar_pcie *pcie = &host->pcie; in rcar_pcie_resume_noirq()
1123 /* Re-establish the PCIe link */ in rcar_pcie_resume_noirq()
1136 .name = "rcar-pcie",
1152 { .compatible = "renesas,pcie-r8a7779" },
1153 { .compatible = "renesas,pcie-r8a7790" },
1154 { .compatible = "renesas,pcie-r8a7791" },
1155 { .compatible = "renesas,pcie-rcar-gen2" },