Skip to content

Commit a042746

Browse files
tkiskybjorn-helgaas
authored andcommitted
PCI: imx6: Add speed change timeout message
Currently, the timeout is never detected as count has a value of -1 if a timeout happens, but the code is checking for 0. Also, this patch removes the unneeded final wait if a timeout occurs. [bhelgaas: reworked starting from http://lkml.kernel.org/r/[email protected]] Signed-off-by: Troy Kisky <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 5ebe6af commit a042746

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

drivers/pci/host/pci-imx6.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,23 @@ static int imx6_pcie_wait_for_link(struct pcie_port *pp)
352352
return 0;
353353
}
354354

355+
static int imx6_pcie_wait_for_speed_change(struct pcie_port *pp)
356+
{
357+
uint32_t tmp;
358+
unsigned int retries;
359+
360+
for (retries = 0; retries < 200; retries++) {
361+
tmp = readl(pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);
362+
/* Test if the speed change finished. */
363+
if (!(tmp & PORT_LOGIC_SPEED_CHANGE))
364+
return 0;
365+
usleep_range(100, 1000);
366+
}
367+
368+
dev_err(pp->dev, "Speed change timeout\n");
369+
return -EINVAL;
370+
}
371+
355372
static irqreturn_t imx6_pcie_msi_handler(int irq, void *arg)
356373
{
357374
struct pcie_port *pp = arg;
@@ -363,7 +380,7 @@ static int imx6_pcie_start_link(struct pcie_port *pp)
363380
{
364381
struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
365382
uint32_t tmp;
366-
int ret, count;
383+
int ret;
367384

368385
/*
369386
* Force Gen1 operation when starting the link. In case the link is
@@ -397,29 +414,22 @@ static int imx6_pcie_start_link(struct pcie_port *pp)
397414
tmp |= PORT_LOGIC_SPEED_CHANGE;
398415
writel(tmp, pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);
399416

400-
count = 200;
401-
while (count--) {
402-
tmp = readl(pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);
403-
/* Test if the speed change finished. */
404-
if (!(tmp & PORT_LOGIC_SPEED_CHANGE))
405-
break;
406-
usleep_range(100, 1000);
417+
ret = imx6_pcie_wait_for_speed_change(pp);
418+
if (ret) {
419+
dev_err(pp->dev, "Failed to bring link up!\n");
420+
return ret;
407421
}
408422

409423
/* Make sure link training is finished as well! */
410-
if (count)
411-
ret = imx6_pcie_wait_for_link(pp);
412-
else
413-
ret = -EINVAL;
414-
424+
ret = imx6_pcie_wait_for_link(pp);
415425
if (ret) {
416426
dev_err(pp->dev, "Failed to bring link up!\n");
417-
} else {
418-
tmp = readl(pp->dbi_base + 0x80);
419-
dev_dbg(pp->dev, "Link up, Gen=%i\n", (tmp >> 16) & 0xf);
427+
return ret;
420428
}
421429

422-
return ret;
430+
tmp = readl(pp->dbi_base + 0x80);
431+
dev_dbg(pp->dev, "Link up, Gen=%i\n", (tmp >> 16) & 0xf);
432+
return 0;
423433
}
424434

425435
static void imx6_pcie_host_init(struct pcie_port *pp)

0 commit comments

Comments
 (0)