提交 7faebda2 编写于 作者: S Shawn Lin 提交者: Bjorn Helgaas

PCI: rockchip: Use readl_poll_timeout() instead of open-coding it

Use readl_poll_timeout() instead of open-coding it.
Signed-off-by: NShawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
上级 afc9595e
...@@ -188,8 +188,11 @@ ...@@ -188,8 +188,11 @@
(PCIE_ECAM_BUS(bus) | PCIE_ECAM_DEV(dev) | \ (PCIE_ECAM_BUS(bus) | PCIE_ECAM_DEV(dev) | \
PCIE_ECAM_FUNC(func) | PCIE_ECAM_REG(reg)) PCIE_ECAM_FUNC(func) | PCIE_ECAM_REG(reg))
#define PCIE_LINK_IS_L2(x) \ #define PCIE_LINK_IS_L2(x) \
(((x) & PCIE_CLIENT_DEBUG_LTSSM_MASK) == \ (((x) & PCIE_CLIENT_DEBUG_LTSSM_MASK) == PCIE_CLIENT_DEBUG_LTSSM_L2)
PCIE_CLIENT_DEBUG_LTSSM_L2) #define PCIE_LINK_UP(x) \
(((x) & PCIE_CLIENT_LINK_STATUS_MASK) == PCIE_CLIENT_LINK_STATUS_UP)
#define PCIE_LINK_IS_GEN2(x) \
(((x) & PCIE_CORE_PL_CONF_SPEED_MASK) == PCIE_CORE_PL_CONF_SPEED_5G)
#define RC_REGION_0_ADDR_TRANS_H 0x00000000 #define RC_REGION_0_ADDR_TRANS_H 0x00000000
#define RC_REGION_0_ADDR_TRANS_L 0x00000000 #define RC_REGION_0_ADDR_TRANS_L 0x00000000
...@@ -463,7 +466,6 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip) ...@@ -463,7 +466,6 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
struct device *dev = rockchip->dev; struct device *dev = rockchip->dev;
int err; int err;
u32 status; u32 status;
unsigned long timeout;
gpiod_set_value(rockchip->ep_gpio, 0); gpiod_set_value(rockchip->ep_gpio, 0);
...@@ -604,23 +606,12 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip) ...@@ -604,23 +606,12 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
gpiod_set_value(rockchip->ep_gpio, 1); gpiod_set_value(rockchip->ep_gpio, 1);
/* 500ms timeout value should be enough for Gen1/2 training */ /* 500ms timeout value should be enough for Gen1/2 training */
timeout = jiffies + msecs_to_jiffies(500); err = readl_poll_timeout(rockchip->apb_base + PCIE_CLIENT_BASIC_STATUS1,
status, PCIE_LINK_UP(status), 20,
for (;;) { 500 * USEC_PER_MSEC);
status = rockchip_pcie_read(rockchip, if (err) {
PCIE_CLIENT_BASIC_STATUS1); dev_err(dev, "PCIe link training gen1 timeout!\n");
if ((status & PCIE_CLIENT_LINK_STATUS_MASK) == return -ETIMEDOUT;
PCIE_CLIENT_LINK_STATUS_UP) {
dev_dbg(dev, "PCIe link training gen1 pass!\n");
break;
}
if (time_after(jiffies, timeout)) {
dev_err(dev, "PCIe link training gen1 timeout!\n");
return -ETIMEDOUT;
}
msleep(20);
} }
if (rockchip->link_gen == 2) { if (rockchip->link_gen == 2) {
...@@ -632,22 +623,11 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip) ...@@ -632,22 +623,11 @@ static int rockchip_pcie_init_port(struct rockchip_pcie *rockchip)
status |= PCI_EXP_LNKCTL_RL; status |= PCI_EXP_LNKCTL_RL;
rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_LCS); rockchip_pcie_write(rockchip, status, PCIE_RC_CONFIG_LCS);
timeout = jiffies + msecs_to_jiffies(500); err = readl_poll_timeout(rockchip->apb_base + PCIE_CORE_CTRL,
for (;;) { status, PCIE_LINK_IS_GEN2(status), 20,
status = rockchip_pcie_read(rockchip, PCIE_CORE_CTRL); 500 * USEC_PER_MSEC);
if ((status & PCIE_CORE_PL_CONF_SPEED_MASK) == if (err)
PCIE_CORE_PL_CONF_SPEED_5G) { dev_dbg(dev, "PCIe link training gen2 timeout, fall back to gen1!\n");
dev_dbg(dev, "PCIe link training gen2 pass!\n");
break;
}
if (time_after(jiffies, timeout)) {
dev_dbg(dev, "PCIe link training gen2 timeout, fall back to gen1!\n");
break;
}
msleep(20);
}
} }
/* Check the final link width from negotiated lane counter from MGMT */ /* Check the final link width from negotiated lane counter from MGMT */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册