2018-01-27 02:50:27 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-06-21 15:24:54 +08:00
|
|
|
/*
|
2017-09-02 05:35:50 +08:00
|
|
|
* Synopsys DesignWare PCIe host controller driver
|
2013-06-21 15:24:54 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Samsung Electronics Co., Ltd.
|
|
|
|
* http://www.samsung.com
|
|
|
|
*
|
|
|
|
* Author: Jingoo Han <jg1.han@samsung.com>
|
|
|
|
*/
|
|
|
|
|
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-11 04:44:35 +08:00
|
|
|
#include <linux/delay.h>
|
2017-02-15 21:18:17 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/types.h>
|
2013-06-21 15:24:54 +08:00
|
|
|
|
2013-07-31 16:14:10 +08:00
|
|
|
#include "pcie-designware.h"
|
2013-06-21 15:24:54 +08:00
|
|
|
|
2016-03-11 04:44:44 +08:00
|
|
|
/* PCIe Port Logic registers */
|
|
|
|
#define PLR_OFFSET 0x700
|
|
|
|
#define PCIE_PHY_DEBUG_R1 (PLR_OFFSET + 0x2c)
|
2016-08-18 04:57:37 +08:00
|
|
|
#define PCIE_PHY_DEBUG_R1_LINK_UP (0x1 << 4)
|
|
|
|
#define PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING (0x1 << 29)
|
2016-03-11 04:44:44 +08:00
|
|
|
|
2017-02-15 21:18:12 +08:00
|
|
|
int dw_pcie_read(void __iomem *addr, int size, u32 *val)
|
2013-06-21 15:24:54 +08:00
|
|
|
{
|
2015-10-09 03:27:53 +08:00
|
|
|
if ((uintptr_t)addr & (size - 1)) {
|
|
|
|
*val = 0;
|
|
|
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:18:16 +08:00
|
|
|
if (size == 4) {
|
2015-10-09 03:27:43 +08:00
|
|
|
*val = readl(addr);
|
2017-02-15 21:18:16 +08:00
|
|
|
} else if (size == 2) {
|
2015-10-09 03:27:48 +08:00
|
|
|
*val = readw(addr);
|
2017-02-15 21:18:16 +08:00
|
|
|
} else if (size == 1) {
|
2015-10-09 03:27:48 +08:00
|
|
|
*val = readb(addr);
|
2017-02-15 21:18:16 +08:00
|
|
|
} else {
|
2015-10-09 03:27:43 +08:00
|
|
|
*val = 0;
|
2013-06-21 15:24:54 +08:00
|
|
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
2015-10-09 03:27:43 +08:00
|
|
|
}
|
2013-06-21 15:24:54 +08:00
|
|
|
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:18:12 +08:00
|
|
|
int dw_pcie_write(void __iomem *addr, int size, u32 val)
|
2013-06-21 15:24:54 +08:00
|
|
|
{
|
2015-10-09 03:27:53 +08:00
|
|
|
if ((uintptr_t)addr & (size - 1))
|
|
|
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
|
|
|
|
2013-06-21 15:24:54 +08:00
|
|
|
if (size == 4)
|
|
|
|
writel(val, addr);
|
|
|
|
else if (size == 2)
|
2015-10-09 03:27:48 +08:00
|
|
|
writew(val, addr);
|
2013-06-21 15:24:54 +08:00
|
|
|
else if (size == 1)
|
2015-10-09 03:27:48 +08:00
|
|
|
writeb(val, addr);
|
2013-06-21 15:24:54 +08:00
|
|
|
else
|
|
|
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
|
|
|
|
|
|
|
return PCIBIOS_SUCCESSFUL;
|
|
|
|
}
|
|
|
|
|
2017-03-13 21:43:26 +08:00
|
|
|
u32 __dw_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base, u32 reg,
|
|
|
|
size_t size)
|
2013-06-21 15:24:54 +08:00
|
|
|
{
|
2017-03-13 21:43:26 +08:00
|
|
|
int ret;
|
|
|
|
u32 val;
|
2016-08-18 03:17:58 +08:00
|
|
|
|
2017-03-13 21:43:26 +08:00
|
|
|
if (pci->ops->read_dbi)
|
|
|
|
return pci->ops->read_dbi(pci, base, reg, size);
|
|
|
|
|
|
|
|
ret = dw_pcie_read(base + reg, size, &val);
|
|
|
|
if (ret)
|
|
|
|
dev_err(pci->dev, "read DBI address failed\n");
|
|
|
|
|
|
|
|
return val;
|
2013-06-21 15:24:54 +08:00
|
|
|
}
|
|
|
|
|
2017-03-13 21:43:26 +08:00
|
|
|
void __dw_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base, u32 reg,
|
|
|
|
size_t size, u32 val)
|
2013-06-21 15:24:54 +08:00
|
|
|
{
|
2017-03-13 21:43:26 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (pci->ops->write_dbi) {
|
|
|
|
pci->ops->write_dbi(pci, base, reg, size, val);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = dw_pcie_write(base + reg, size, val);
|
|
|
|
if (ret)
|
|
|
|
dev_err(pci->dev, "write DBI address failed\n");
|
2013-06-21 15:24:54 +08:00
|
|
|
}
|
|
|
|
|
2017-03-13 21:43:27 +08:00
|
|
|
static u32 dw_pcie_readl_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg)
|
2016-08-10 18:02:39 +08:00
|
|
|
{
|
|
|
|
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
|
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
return dw_pcie_readl_dbi(pci, offset + reg);
|
2016-08-10 18:02:39 +08:00
|
|
|
}
|
|
|
|
|
2017-03-13 21:43:27 +08:00
|
|
|
static void dw_pcie_writel_ob_unroll(struct dw_pcie *pci, u32 index, u32 reg,
|
|
|
|
u32 val)
|
2016-08-10 18:02:39 +08:00
|
|
|
{
|
|
|
|
u32 offset = PCIE_GET_ATU_OUTB_UNR_REG_OFFSET(index);
|
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
dw_pcie_writel_dbi(pci, offset + reg, val);
|
2016-08-10 18:02:39 +08:00
|
|
|
}
|
|
|
|
|
2017-07-17 21:13:34 +08:00
|
|
|
static void dw_pcie_prog_outbound_atu_unroll(struct dw_pcie *pci, int index,
|
|
|
|
int type, u64 cpu_addr,
|
|
|
|
u64 pci_addr, u32 size)
|
2017-03-13 21:43:27 +08:00
|
|
|
{
|
|
|
|
u32 retries, val;
|
|
|
|
|
|
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_BASE,
|
|
|
|
lower_32_bits(cpu_addr));
|
|
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_BASE,
|
|
|
|
upper_32_bits(cpu_addr));
|
|
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LIMIT,
|
|
|
|
lower_32_bits(cpu_addr + size - 1));
|
|
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET,
|
|
|
|
lower_32_bits(pci_addr));
|
|
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
|
|
|
|
upper_32_bits(pci_addr));
|
|
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL1,
|
|
|
|
type);
|
|
|
|
dw_pcie_writel_ob_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
|
|
|
|
PCIE_ATU_ENABLE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure ATU enable takes effect before any subsequent config
|
|
|
|
* and I/O accesses.
|
|
|
|
*/
|
|
|
|
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
|
|
|
|
val = dw_pcie_readl_ob_unroll(pci, index,
|
|
|
|
PCIE_ATU_UNR_REGION_CTRL2);
|
|
|
|
if (val & PCIE_ATU_ENABLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
usleep_range(LINK_WAIT_IATU_MIN, LINK_WAIT_IATU_MAX);
|
|
|
|
}
|
|
|
|
dev_err(pci->dev, "outbound iATU is not being enabled\n");
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:18:17 +08:00
|
|
|
void dw_pcie_prog_outbound_atu(struct dw_pcie *pci, int index, int type,
|
|
|
|
u64 cpu_addr, u64 pci_addr, u32 size)
|
2015-04-30 16:22:28 +08:00
|
|
|
{
|
2016-08-18 02:26:07 +08:00
|
|
|
u32 retries, val;
|
2015-12-18 20:38:55 +08:00
|
|
|
|
2017-03-13 21:43:22 +08:00
|
|
|
if (pci->ops->cpu_addr_fixup)
|
PCI: dwc: Make cpu_addr_fixup take struct dw_pcie as argument
The current cpu addr fixup mask for ARTPEC-6, GENMASK(27, 0), is wrong.
The correct cpu addr fixup mask for ARTPEC-6 is GENMASK(28, 0).
However, having a hardcoded cpu addr fixup mask in each driver is
arguably wrong.
A device tree property called something like "cpu-addr-fixup-mask"
would have been a better solution.
Introducing such a property is not needed though, since we already have
pp->cfg0_base and ep->phys_base, which is derived from already existing
device tree properties.
It is also worth noting that for ARTPEC-7, hardcoding the cpu addr fixup
mask is not possible, since it uses a High Address Bits Look Up Table,
which means that it can, at runtime, map the PCIe window to an arbitrary
address in the 32-bit address space.
By using pp->cfg0_base and ep->phys_base, we avoid hardcoding a mask
in each driver. This should work for ARTPEC-6, DRA7xx, and ARTPEC-7.
I have not changed the code in DRA7xx though, since their existing
code works, but if they want, they could use the same logic as
artpec6_pcie_cpu_addr_fixup, and thus remove their hardcoded mask.
The reason why the fixup mask is needed is explained in commit f4c55c5a3f7f
("PCI: designware: Program ATU with untranslated address").
Signed-off-by: Niklas Cassel <niklas.cassel@axis.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Kishon Vijay Abraham I <kishon@ti.com>
2017-12-20 07:29:36 +08:00
|
|
|
cpu_addr = pci->ops->cpu_addr_fixup(pci, cpu_addr);
|
2017-03-13 21:43:22 +08:00
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
if (pci->iatu_unroll_enabled) {
|
2017-03-13 21:43:27 +08:00
|
|
|
dw_pcie_prog_outbound_atu_unroll(pci, index, type, cpu_addr,
|
|
|
|
pci_addr, size);
|
|
|
|
return;
|
2016-08-10 18:02:39 +08:00
|
|
|
}
|
2015-12-18 20:38:55 +08:00
|
|
|
|
2017-03-13 21:43:27 +08:00
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_VIEWPORT,
|
|
|
|
PCIE_ATU_REGION_OUTBOUND | index);
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_LOWER_BASE,
|
|
|
|
lower_32_bits(cpu_addr));
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_UPPER_BASE,
|
|
|
|
upper_32_bits(cpu_addr));
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_LIMIT,
|
|
|
|
lower_32_bits(cpu_addr + size - 1));
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_LOWER_TARGET,
|
|
|
|
lower_32_bits(pci_addr));
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_UPPER_TARGET,
|
|
|
|
upper_32_bits(pci_addr));
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR1, type);
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR2, PCIE_ATU_ENABLE);
|
|
|
|
|
2015-12-18 20:38:55 +08:00
|
|
|
/*
|
|
|
|
* Make sure ATU enable takes effect before any subsequent config
|
|
|
|
* and I/O accesses.
|
|
|
|
*/
|
2016-08-18 02:26:07 +08:00
|
|
|
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
|
2017-03-13 21:43:27 +08:00
|
|
|
val = dw_pcie_readl_dbi(pci, PCIE_ATU_CR2);
|
2017-07-18 14:48:21 +08:00
|
|
|
if (val & PCIE_ATU_ENABLE)
|
2016-08-18 02:26:07 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
usleep_range(LINK_WAIT_IATU_MIN, LINK_WAIT_IATU_MAX);
|
|
|
|
}
|
2017-03-13 21:43:27 +08:00
|
|
|
dev_err(pci->dev, "outbound iATU is not being enabled\n");
|
2015-04-30 16:22:28 +08:00
|
|
|
}
|
|
|
|
|
2017-03-27 17:45:05 +08:00
|
|
|
static u32 dw_pcie_readl_ib_unroll(struct dw_pcie *pci, u32 index, u32 reg)
|
|
|
|
{
|
|
|
|
u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET(index);
|
|
|
|
|
|
|
|
return dw_pcie_readl_dbi(pci, offset + reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dw_pcie_writel_ib_unroll(struct dw_pcie *pci, u32 index, u32 reg,
|
|
|
|
u32 val)
|
|
|
|
{
|
|
|
|
u32 offset = PCIE_GET_ATU_INB_UNR_REG_OFFSET(index);
|
|
|
|
|
|
|
|
dw_pcie_writel_dbi(pci, offset + reg, val);
|
|
|
|
}
|
|
|
|
|
2017-07-17 21:13:34 +08:00
|
|
|
static int dw_pcie_prog_inbound_atu_unroll(struct dw_pcie *pci, int index,
|
|
|
|
int bar, u64 cpu_addr,
|
|
|
|
enum dw_pcie_as_type as_type)
|
2017-03-27 17:45:05 +08:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
u32 retries, val;
|
|
|
|
|
|
|
|
dw_pcie_writel_ib_unroll(pci, index, PCIE_ATU_UNR_LOWER_TARGET,
|
|
|
|
lower_32_bits(cpu_addr));
|
|
|
|
dw_pcie_writel_ib_unroll(pci, index, PCIE_ATU_UNR_UPPER_TARGET,
|
|
|
|
upper_32_bits(cpu_addr));
|
|
|
|
|
|
|
|
switch (as_type) {
|
|
|
|
case DW_PCIE_AS_MEM:
|
|
|
|
type = PCIE_ATU_TYPE_MEM;
|
|
|
|
break;
|
|
|
|
case DW_PCIE_AS_IO:
|
|
|
|
type = PCIE_ATU_TYPE_IO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dw_pcie_writel_ib_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL1, type);
|
|
|
|
dw_pcie_writel_ib_unroll(pci, index, PCIE_ATU_UNR_REGION_CTRL2,
|
|
|
|
PCIE_ATU_ENABLE |
|
|
|
|
PCIE_ATU_BAR_MODE_ENABLE | (bar << 8));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure ATU enable takes effect before any subsequent config
|
|
|
|
* and I/O accesses.
|
|
|
|
*/
|
|
|
|
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
|
|
|
|
val = dw_pcie_readl_ib_unroll(pci, index,
|
|
|
|
PCIE_ATU_UNR_REGION_CTRL2);
|
|
|
|
if (val & PCIE_ATU_ENABLE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
usleep_range(LINK_WAIT_IATU_MIN, LINK_WAIT_IATU_MAX);
|
|
|
|
}
|
|
|
|
dev_err(pci->dev, "inbound iATU is not being enabled\n");
|
|
|
|
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dw_pcie_prog_inbound_atu(struct dw_pcie *pci, int index, int bar,
|
|
|
|
u64 cpu_addr, enum dw_pcie_as_type as_type)
|
|
|
|
{
|
|
|
|
int type;
|
|
|
|
u32 retries, val;
|
|
|
|
|
|
|
|
if (pci->iatu_unroll_enabled)
|
|
|
|
return dw_pcie_prog_inbound_atu_unroll(pci, index, bar,
|
|
|
|
cpu_addr, as_type);
|
|
|
|
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_VIEWPORT, PCIE_ATU_REGION_INBOUND |
|
|
|
|
index);
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_LOWER_TARGET, lower_32_bits(cpu_addr));
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_UPPER_TARGET, upper_32_bits(cpu_addr));
|
|
|
|
|
|
|
|
switch (as_type) {
|
|
|
|
case DW_PCIE_AS_MEM:
|
|
|
|
type = PCIE_ATU_TYPE_MEM;
|
|
|
|
break;
|
|
|
|
case DW_PCIE_AS_IO:
|
|
|
|
type = PCIE_ATU_TYPE_IO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR1, type);
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR2, PCIE_ATU_ENABLE
|
|
|
|
| PCIE_ATU_BAR_MODE_ENABLE | (bar << 8));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure ATU enable takes effect before any subsequent config
|
|
|
|
* and I/O accesses.
|
|
|
|
*/
|
|
|
|
for (retries = 0; retries < LINK_WAIT_MAX_IATU_RETRIES; retries++) {
|
|
|
|
val = dw_pcie_readl_dbi(pci, PCIE_ATU_CR2);
|
|
|
|
if (val & PCIE_ATU_ENABLE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
usleep_range(LINK_WAIT_IATU_MIN, LINK_WAIT_IATU_MAX);
|
|
|
|
}
|
|
|
|
dev_err(pci->dev, "inbound iATU is not being enabled\n");
|
|
|
|
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dw_pcie_disable_atu(struct dw_pcie *pci, int index,
|
|
|
|
enum dw_pcie_region_type type)
|
|
|
|
{
|
|
|
|
int region;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DW_PCIE_REGION_INBOUND:
|
|
|
|
region = PCIE_ATU_REGION_INBOUND;
|
|
|
|
break;
|
|
|
|
case DW_PCIE_REGION_OUTBOUND:
|
|
|
|
region = PCIE_ATU_REGION_OUTBOUND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_VIEWPORT, region | index);
|
|
|
|
dw_pcie_writel_dbi(pci, PCIE_ATU_CR2, ~PCIE_ATU_ENABLE);
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
int dw_pcie_wait_for_link(struct dw_pcie *pci)
|
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-11 04:44:35 +08:00
|
|
|
{
|
|
|
|
int retries;
|
|
|
|
|
|
|
|
/* check if the link is up or not */
|
|
|
|
for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) {
|
2017-02-15 21:18:14 +08:00
|
|
|
if (dw_pcie_link_up(pci)) {
|
|
|
|
dev_info(pci->dev, "link up\n");
|
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-11 04:44:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX);
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
dev_err(pci->dev, "phy link never came up\n");
|
PCI: designware: Add generic dw_pcie_wait_for_link()
Several DesignWare-based drivers (dra7xx, exynos, imx6, keystone, qcom, and
spear13xx) had similar loops waiting for the link to come up.
Add a generic dw_pcie_wait_for_link() for use by all these drivers so the
waiting is done consistently, e.g., always using usleep_range() rather than
mdelay() and using similar timeouts and retry counts.
Note that this changes the Keystone link training/wait for link strategy,
so we initiate link training, then wait longer for the link to come up
before re-initiating link training.
[bhelgaas: changelog, split into its own patch, update pci-keystone.c, pcie-qcom.c]
Signed-off-by: Joao Pinto <jpinto@synopsys.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Acked-by: Pratyush Anand <pratyush.anand@gmail.com>
2016-03-11 04:44:35 +08:00
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
int dw_pcie_link_up(struct dw_pcie *pci)
|
2013-07-31 16:14:10 +08:00
|
|
|
{
|
2016-03-11 04:44:44 +08:00
|
|
|
u32 val;
|
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
if (pci->ops->link_up)
|
|
|
|
return pci->ops->link_up(pci);
|
2016-01-06 05:48:11 +08:00
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
val = readl(pci->dbi_base + PCIE_PHY_DEBUG_R1);
|
2016-08-18 04:57:37 +08:00
|
|
|
return ((val & PCIE_PHY_DEBUG_R1_LINK_UP) &&
|
|
|
|
(!(val & PCIE_PHY_DEBUG_R1_LINK_IN_TRAINING)));
|
2013-07-31 16:14:10 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 21:18:17 +08:00
|
|
|
void dw_pcie_setup(struct dw_pcie *pci)
|
2013-06-21 15:24:54 +08:00
|
|
|
{
|
2017-02-15 21:18:15 +08:00
|
|
|
int ret;
|
2013-06-21 15:24:54 +08:00
|
|
|
u32 val;
|
2017-02-15 21:18:17 +08:00
|
|
|
u32 lanes;
|
2017-02-15 21:18:15 +08:00
|
|
|
struct device *dev = pci->dev;
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(np, "num-lanes", &lanes);
|
|
|
|
if (ret)
|
|
|
|
lanes = 0;
|
2013-06-21 15:24:54 +08:00
|
|
|
|
2014-04-15 04:22:54 +08:00
|
|
|
/* set the number of lanes */
|
2017-02-15 21:18:14 +08:00
|
|
|
val = dw_pcie_readl_dbi(pci, PCIE_PORT_LINK_CONTROL);
|
2013-06-21 15:24:54 +08:00
|
|
|
val &= ~PORT_LINK_MODE_MASK;
|
2017-02-15 21:18:15 +08:00
|
|
|
switch (lanes) {
|
2013-07-31 16:14:10 +08:00
|
|
|
case 1:
|
|
|
|
val |= PORT_LINK_MODE_1_LANES;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
val |= PORT_LINK_MODE_2_LANES;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
val |= PORT_LINK_MODE_4_LANES;
|
|
|
|
break;
|
2015-05-13 14:44:34 +08:00
|
|
|
case 8:
|
|
|
|
val |= PORT_LINK_MODE_8_LANES;
|
|
|
|
break;
|
2015-09-29 00:03:10 +08:00
|
|
|
default:
|
2017-02-15 21:18:15 +08:00
|
|
|
dev_err(pci->dev, "num-lanes %u: invalid value\n", lanes);
|
2015-09-29 00:03:10 +08:00
|
|
|
return;
|
2013-07-31 16:14:10 +08:00
|
|
|
}
|
2017-02-15 21:18:14 +08:00
|
|
|
dw_pcie_writel_dbi(pci, PCIE_PORT_LINK_CONTROL, val);
|
2013-06-21 15:24:54 +08:00
|
|
|
|
|
|
|
/* set link width speed control register */
|
2017-02-15 21:18:14 +08:00
|
|
|
val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
|
2013-06-21 15:24:54 +08:00
|
|
|
val &= ~PORT_LOGIC_LINK_WIDTH_MASK;
|
2017-02-15 21:18:15 +08:00
|
|
|
switch (lanes) {
|
2013-07-31 16:14:10 +08:00
|
|
|
case 1:
|
|
|
|
val |= PORT_LOGIC_LINK_WIDTH_1_LANES;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
val |= PORT_LOGIC_LINK_WIDTH_2_LANES;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
val |= PORT_LOGIC_LINK_WIDTH_4_LANES;
|
|
|
|
break;
|
2015-05-13 14:44:34 +08:00
|
|
|
case 8:
|
|
|
|
val |= PORT_LOGIC_LINK_WIDTH_8_LANES;
|
|
|
|
break;
|
2013-07-31 16:14:10 +08:00
|
|
|
}
|
2017-02-15 21:18:14 +08:00
|
|
|
dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
|
2013-06-21 15:24:54 +08:00
|
|
|
}
|