staticint rcar_pcie_wakeup(struct device *pcie_dev, void __iomem *pcie_base)
{
u32 pmsr, val; int ret = 0;
if (!pcie_base || pm_runtime_suspended(pcie_dev)) return -EINVAL;
pmsr = readl(pcie_base + PMSR);
/* * Test if the PCIe controller received PM_ENTER_L1 DLLP and * the PCIe controller is not in L1 link state. If true, apply * fix, which will put the controller into L1 link state, from * which it can return to L0s/L0 on its own.
*/ if ((pmsr & PMEL1RX) && ((pmsr & PMSTATE) != PMSTATE_L1)) {
writel(L1IATN, pcie_base + PMCTLR);
ret = readl_poll_timeout_atomic(pcie_base + PMSR, val,
val & L1FAEG, 10, 1000); if (ret) {
dev_warn_ratelimited(pcie_dev, "Timeout waiting for L1 link state, ret=%d\n",
ret);
}
writel(L1FAEG | PMEL1RX, pcie_base + PMSR);
}
/* Serialization is provided by 'pci_lock' in drivers/pci/access.c */ staticint rcar_pcie_config_access(struct rcar_pcie_host *host, unsignedchar access_type, struct pci_bus *bus, unsignedint devfn, int where, u32 *data)
{ struct rcar_pcie *pcie = &host->pcie; unsignedint dev, func, reg, index; int ret;
/* Wake the bus up in case it is in L1 state. */
ret = rcar_pcie_wakeup(pcie->dev, pcie->base); if (ret) {
PCI_SET_ERROR_RESPONSE(data); return PCIBIOS_SET_FAILED;
}
dev = PCI_SLOT(devfn);
func = PCI_FUNC(devfn);
reg = where & ~3;
index = reg / 4;
/* * While each channel has its own memory-mapped extended config * space, it's generally only accessible when in endpoint mode. * When in root complex mode, the controller is unable to target * itself with either type 0 or type 1 accesses, and indeed, any * controller-initiated target transfer to its own config space * results in a completer abort. * * Each channel effectively only supports a single device, but as * the same channel <-> device access works for any PCI_SLOT() * value, we cheat a bit here and bind the controller's config * space to devfn 0 in order to enable self-enumeration. In this * case the regular ECAR/ECDR path is sidelined and the mangled * config access itself is initiated as an internal bus transaction.
*/ if (pci_is_root_bus(bus)) { if (dev != 0) return PCIBIOS_DEVICE_NOT_FOUND;
/* Set the PIO address */
rcar_pci_write_reg(pcie, PCIE_CONF_BUS(bus->number) |
PCIE_CONF_DEV(dev) | PCIE_CONF_FUNC(func) | reg, PCIECAR);
/* Enable the configuration access */ if (pci_is_root_bus(bus->parent))
rcar_pci_write_reg(pcie, PCIECCTLR_CCIE | TYPE0, PCIECCTLR); else
rcar_pci_write_reg(pcie, PCIECCTLR_CCIE | TYPE1, PCIECCTLR);
/* Check for errors */ if (rcar_pci_read_reg(pcie, PCIEERRFR) & UNSUPPORTED_REQUEST) return PCIBIOS_DEVICE_NOT_FOUND;
/* Check for master and target aborts */ if (rcar_read_conf(pcie, RCONF(PCI_STATUS)) &
(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT)) return PCIBIOS_DEVICE_NOT_FOUND;
if (access_type == RCAR_PCI_ACCESS_READ)
ret = rcar_pci_read_reg_workaround(pcie, data, PCIECDR); else
ret = rcar_pci_write_reg_workaround(pcie, *data, PCIECDR);
/* Disable the configuration access */
rcar_pci_write_reg(pcie, 0, PCIECCTLR);
return ret;
}
staticint rcar_pcie_read_conf(struct pci_bus *bus, unsignedint devfn, int where, int size, u32 *val)
{ struct rcar_pcie_host *host = bus->sysdata; int ret;
ret = rcar_pcie_config_access(host, RCAR_PCI_ACCESS_READ,
bus, devfn, where, val); if (ret != PCIBIOS_SUCCESSFUL) return ret;
/* Ignore errors as they will be dealt with if the data link is down */
phy_wait_for_ack(pcie);
}
staticint rcar_pcie_hw_init(struct rcar_pcie *pcie)
{ int err;
/* Begin initialization */
rcar_pci_write_reg(pcie, 0, PCIETCTLR);
/* Set mode */
rcar_pci_write_reg(pcie, 1, PCIEMSR);
err = rcar_pcie_wait_for_phyrdy(pcie); if (err) return err;
/* * Initial header for port config space is type 1, set the device * class to match. Hardware takes care of propagating the IDSETR * settings, so there is no need to bother with a quirk.
*/
rcar_pci_write_reg(pcie, PCI_CLASS_BRIDGE_PCI_NORMAL << 8, IDSETR1);
/* * Setup Secondary Bus Number & Subordinate Bus Number, even though * they aren't used, to avoid bridge being detected as broken.
*/
rcar_rmw32(pcie, RCONF(PCI_SECONDARY_BUS), 0xff, 1);
rcar_rmw32(pcie, RCONF(PCI_SUBORDINATE_BUS), 0xff, 1);
/* * These settings come from the R-Car Series, 2nd Generation User's * Manual, section 50.3.1 (2) Initialization of the physical layer.
*/
rcar_pci_write_reg(pcie, 0x000f0030, GEN2_PCIEPHYADDR);
rcar_pci_write_reg(pcie, 0x00381203, GEN2_PCIEPHYDATA);
rcar_pci_write_reg(pcie, 0x00000001, GEN2_PCIEPHYCTRL);
rcar_pci_write_reg(pcie, 0x00000006, GEN2_PCIEPHYCTRL);
rcar_pci_write_reg(pcie, 0x000f0054, GEN2_PCIEPHYADDR); /* The following value is for DC connection, no termination resistor */
rcar_pci_write_reg(pcie, 0x13802007, GEN2_PCIEPHYDATA);
rcar_pci_write_reg(pcie, 0x00000001, GEN2_PCIEPHYCTRL);
rcar_pci_write_reg(pcie, 0x00000006, GEN2_PCIEPHYCTRL);
return 0;
}
staticint rcar_pcie_phy_init_gen3(struct rcar_pcie_host *host)
{ int err;
err = phy_init(host->phy); if (err) return err;
err = phy_power_on(host->phy); if (err)
phy_exit(host->phy);
err = of_address_to_resource(dev->of_node, 0, &res); if (err) return err;
err = rcar_allocate_domains(msi); if (err) return err;
/* Two IRQs are for MSI, but they are also used for non-MSI IRQs */
err = devm_request_irq(dev, msi->irq1, rcar_pcie_msi_irq,
IRQF_SHARED | IRQF_NO_THREAD,
rcar_msi_bottom_chip.name, host); if (err < 0) {
dev_err(dev, "failed to request IRQ: %d\n", err); goto err;
}
/* Disable all MSIs */
rcar_pci_write_reg(pcie, 0, PCIEMSIIER);
/* * Setup MSI data target using RC base address, which is guaranteed * to be in the low 32bit range on any R-Car HW.
*/
rcar_pci_write_reg(pcie, lower_32_bits(res.start) | MSIFE, PCIEMSIALR);
rcar_pci_write_reg(pcie, upper_32_bits(res.start), PCIEMSIAUR);
if (restype & IORESOURCE_PREFETCH)
flags |= LAM_PREFETCH;
while (cpu_addr < cpu_end) { if (idx >= MAX_NR_INBOUND_MAPS - 1) {
dev_err(pcie->dev, "Failed to map inbound regions!\n"); return -EINVAL;
}
/* * If the size of the range is larger than the alignment of * the start address, we have to use multiple entries to * perform the mapping.
*/ if (cpu_addr > 0) { unsignedlong nr_zeros = __ffs64(cpu_addr);
u64 alignment = 1ULL << nr_zeros;
size = min(size, alignment);
}
/* Hardware supports max 4GiB inbound region */
size = min(size, 1ULL << 32);
/* Design note 346 from Linear Technology says order is not important. */ staticconstchar * const rcar_pcie_supplies[] = { "vpcie1v5", "vpcie3v3", "vpcie12v",
};
err = rcar_pcie_get_resources(host); if (err < 0) {
dev_err(dev, "failed to request resources: %d\n", err); goto err_pm_put;
}
err = clk_prepare_enable(host->bus_clk); if (err) {
dev_err(dev, "failed to enable bus clock: %d\n", err); goto err_unmap_msi_irqs;
}
err = rcar_pcie_parse_map_dma_ranges(host); if (err) goto err_clk_disable;
host->phy_init_fn = of_device_get_match_data(dev);
err = host->phy_init_fn(host); if (err) {
dev_err(dev, "failed to init PCIe PHY\n"); goto err_clk_disable;
}
/* Failure to get a link might just be that no cards are inserted */ if (rcar_pcie_hw_init(pcie)) {
dev_info(dev, "PCIe link down\n");
err = -ENODEV; goto err_phy_shutdown;
}
data = rcar_pci_read_reg(pcie, MACSR);
dev_info(dev, "PCIe x%d: link up\n", (data >> 20) & 0x3f);
if (IS_ENABLED(CONFIG_PCI_MSI)) {
err = rcar_pcie_enable_msi(host); if (err < 0) {
dev_err(dev, "failed to enable MSI support: %d\n",
err); goto err_phy_shutdown;
}
}
err = rcar_pcie_enable(host); if (err) goto err_msi_teardown;
return 0;
err_msi_teardown: if (IS_ENABLED(CONFIG_PCI_MSI))
rcar_pcie_teardown_msi(host);
err_phy_shutdown: if (host->phy) {
phy_power_off(host->phy);
phy_exit(host->phy);
}
err = rcar_pcie_parse_map_dma_ranges(host); if (err) return 0;
/* Failure to get a link might just be that no cards are inserted */
err = host->phy_init_fn(host); if (err) {
dev_info(dev, "PCIe link down\n"); return 0;
}
data = rcar_pci_read_reg(pcie, MACSR);
dev_info(dev, "PCIe x%d: link up\n", (data >> 20) & 0x3f);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.