mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 5/6] i.MX6: pci: Reconcile imx6_pcie_start_link with the kernel code
Date: Thu, 31 Dec 2015 21:58:37 -0800	[thread overview]
Message-ID: <1451627918-31967-5-git-send-email-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <1451627918-31967-1-git-send-email-andrew.smirnov@gmail.com>

Reconcile imx6_pcie_start_link with almost identical
imx6_pcie_establish_link from analogous Linux kernel driver. This
change is purely cosmetical, but refactoring the code this way
simplifies implementation comparison.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/pci-imx6.c | 42 ++++++++++++++++++++++++++----------------
 1 file changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/pci/pci-imx6.c b/drivers/pci/pci-imx6.c
index 84a937f..713007b 100644
--- a/drivers/pci/pci-imx6.c
+++ b/drivers/pci/pci-imx6.c
@@ -362,13 +362,29 @@ static int imx6_pcie_wait_for_link(struct pcie_port *pp)
 	}
 }

+static int imx6_pcie_wait_for_speed_change(struct pcie_port *pp)
+{
+	uint32_t tmp;
+	uint64_t start = get_time_ns();
+
+	while (!is_timeout(start, SECOND)) {
+		tmp = readl(pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);
+		/* Test if the speed change finished. */
+		if (!(tmp & PORT_LOGIC_SPEED_CHANGE))
+			return 0;
+	}
+
+	dev_err(pp->dev, "Speed change timeout\n");
+	return -EINVAL;
+}
+
+
 static int imx6_pcie_start_link(struct pcie_port *pp)
 {
 	struct imx6_pcie *imx6_pcie = to_imx6_pcie(pp);
 	uint32_t tmp;
 	int ret;
 	u32 gpr12;
-	u64 start;

 	/*
 	 * Force Gen1 operation when starting the link.  In case the link is
@@ -403,28 +419,22 @@ static int imx6_pcie_start_link(struct pcie_port *pp)
 	tmp |= PORT_LOGIC_SPEED_CHANGE;
 	writel(tmp, pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);

-	start = get_time_ns();
-	while (!is_timeout(start, SECOND)) {
-		tmp = readl(pp->dbi_base + PCIE_LINK_WIDTH_SPEED_CONTROL);
-		/* Test if the speed change finished. */
-		if (!(tmp & PORT_LOGIC_SPEED_CHANGE))
-			break;
+	ret = imx6_pcie_wait_for_speed_change(pp);
+	if (ret) {
+		dev_err(pp->dev, "Failed to bring link up!\n");
+		return ret;
 	}

 	/* Make sure link training is finished as well! */
-	if (tmp & PORT_LOGIC_SPEED_CHANGE)
-		ret = -EINVAL;
-	else
-		ret = imx6_pcie_wait_for_link(pp);
-
+	ret = imx6_pcie_wait_for_link(pp);
 	if (ret) {
 		dev_err(pp->dev, "Failed to bring link up!\n");
-	} else {
-		tmp = readl(pp->dbi_base + PCIE_RC_LCSR);
-		dev_dbg(pp->dev, "Link up, Gen=%i\n", (tmp >> 16) & 0xf);
+		return ret;
 	}

-	return ret;
+	tmp = readl(pp->dbi_base + PCIE_RC_LCSR);
+	dev_dbg(pp->dev, "Link up, Gen=%i\n", (tmp >> 16) & 0xf);
+	return 0;
 }

 static void imx6_pcie_host_init(struct pcie_port *pp)
--
2.5.0

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-01-01  5:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-01  5:58 [PATCH 1/6] ARM: asm: Add convenience fucntions to access VBAR Andrey Smirnov
2016-01-01  5:58 ` [PATCH 2/6] ARM: mmu: Add VBAR setup Andrey Smirnov
2016-01-04  9:04   ` Sascha Hauer
2016-01-01  5:58 ` [PATCH 3/6] ARM: Fix exception table setup in MMU-less mode Andrey Smirnov
2016-01-04  9:27   ` Sascha Hauer
2016-01-04 17:01     ` Andrey Smirnov
2016-01-05  7:40       ` Sascha Hauer
2016-01-01  5:58 ` [PATCH 4/6] i.MX6: pci: Replace magic number with a named constant Andrey Smirnov
2016-01-07  9:04   ` Lucas Stach
2016-01-08  7:53     ` Sascha Hauer
2016-01-01  5:58 ` Andrey Smirnov [this message]
2016-01-07  9:08   ` [PATCH 5/6] i.MX6: pci: Reconcile imx6_pcie_start_link with the kernel code Lucas Stach
2016-01-01  5:58 ` [PATCH 6/6] i.MX6: pci: Avoid aborts when asserting PCIe reset Andrey Smirnov
2016-01-04  9:30   ` Sascha Hauer
2016-01-07  9:13   ` Lucas Stach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1451627918-31967-5-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox