All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: linux-renesas-soc@vger.kernel.org
Cc: Kieran Bingham <kieran.bingham@ideasonboard.com>,
	LUU HOAI <hoai.luu.ub@renesas.com>
Subject: [RFC PATCH 14/15] drm: rcar-du: dsi: Use read_poll_timeout()
Date: Wed, 23 Jun 2021 06:46:55 +0300	[thread overview]
Message-ID: <20210623034656.10316-15-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <20210623034656.10316-1-laurent.pinchart+renesas@ideasonboard.com>

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c | 114 +++++++++---------------
 1 file changed, 43 insertions(+), 71 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c b/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
index 2ac4171e6c6a..381b5bc9bce1 100644
--- a/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
+++ b/drivers/gpu/drm/rcar-du/rcar_mipi_dsi.c
@@ -8,6 +8,7 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -145,25 +146,21 @@ static void rcar_mipi_dsi_set(struct rcar_mipi_dsi *dsi, u32 reg, u32 set)
 
 static int rcar_mipi_dsi_phtw_test(struct rcar_mipi_dsi *dsi, u32 phtw)
 {
-	unsigned int timeout;
 	u32 status;
+	int ret;
 
 	rcar_mipi_dsi_write(dsi, PHTW, phtw);
 
-	for (timeout = 10; timeout > 0; --timeout) {
-		status = rcar_mipi_dsi_read(dsi, PHTW);
-		if (!(status & PHTW_DWEN) && !(status & PHTW_CWEN))
-			break;
-
-		usleep_range(1000, 2000);
-	}
-
-	if (!timeout) {
-		dev_err(dsi->dev, "failed to test phtw with data %x\n", phtw);
-		return -ETIMEDOUT;
+	ret = read_poll_timeout(rcar_mipi_dsi_read, status,
+				!(status & (PHTW_DWEN | PHTW_CWEN)),
+				2000, 10000, false, dsi, PHTW);
+	if (ret < 0) {
+		dev_err(dsi->dev, "PHY test interface write timeout (0x%08x)\n",
+			phtw);
+		return ret;
 	}
 
-	return timeout;
+	return ret;
 }
 
 /* -----------------------------------------------------------------------------
@@ -458,86 +455,61 @@ static int rcar_mipi_dsi_start_hs_clock(struct rcar_mipi_dsi *dsi)
 	 * In HW manual, we need to check TxDDRClkHS-Q Stable? but it dont
 	 * write how to check. So we skip this check in this patch
 	 */
-	unsigned int timeout;
 	u32 status;
+	int ret;
 
-	/* Start HS clock */
+	/* Start HS clock. */
 	rcar_mipi_dsi_set(dsi, PPICLCR, PPICLCR_TXREQHS);
 
-	for (timeout = 10; timeout > 0; --timeout) {
-		status = rcar_mipi_dsi_read(dsi, PPICLSR);
-
-		if (status & PPICLSR_TOHS) {
-			rcar_mipi_dsi_set(dsi, PPICLSCR, PPICLSCR_TOHS);
-			break;
-		}
-
-		usleep_range(1000, 2000);
-	}
-
-	if (!timeout) {
+	ret = read_poll_timeout(rcar_mipi_dsi_read, status,
+				status & PPICLSR_TOHS,
+				2000, 10000, false, dsi, PPICLSR);
+	if (ret < 0) {
 		dev_err(dsi->dev, "failed to enable HS clock\n");
-		return -ETIMEDOUT;
+		return ret;
 	}
 
-	dev_dbg(dsi->dev, "Start High Speed Clock");
+	rcar_mipi_dsi_set(dsi, PPICLSCR, PPICLSCR_TOHS);
 
 	return 0;
 }
 
 static int rcar_mipi_dsi_start_video(struct rcar_mipi_dsi *dsi)
 {
-	unsigned int timeout;
 	u32 status;
-
-	/* Check status of Tranmission */
-	for (timeout = 10; timeout > 0; --timeout) {
-		status = rcar_mipi_dsi_read(dsi, LINKSR);
-		if (!(status & LINKSR_LPBUSY) && !(status & LINKSR_HSBUSY)) {
-			rcar_mipi_dsi_clr(dsi, TXVMCR, TXVMCR_VFCLR);
-			break;
-		}
-
-		usleep_range(1000, 2000);
+	int ret;
+
+	/* Wait for the link to be ready. */
+	ret = read_poll_timeout(rcar_mipi_dsi_read, status,
+				!(status & (LINKSR_LPBUSY | LINKSR_HSBUSY)),
+				2000, 10000, false, dsi, LINKSR);
+	if (ret < 0) {
+		dev_err(dsi->dev, "Link failed to become ready\n");
+		return ret;
 	}
 
-	if (!timeout) {
-		dev_err(dsi->dev, "Failed to enable Video clock\n");
-		return -ETIMEDOUT;
-	}
+	/* De-assert video FIFO clear. */
+	rcar_mipi_dsi_clr(dsi, TXVMCR, TXVMCR_VFCLR);
 
-	/* Check Clear Video mode FIFO */
-	for (timeout = 10; timeout > 0; --timeout) {
-		status = rcar_mipi_dsi_read(dsi, TXVMSR);
-		if (status & TXVMSR_VFRDY) {
-			rcar_mipi_dsi_set(dsi, TXVMCR, TXVMCR_EN_VIDEO);
-			break;
-		}
-
-		usleep_range(1000, 2000);
+	ret = read_poll_timeout(rcar_mipi_dsi_read, status,
+				status & TXVMSR_VFRDY,
+				2000, 10000, false, dsi, TXVMSR);
+	if (ret < 0) {
+		dev_err(dsi->dev, "Failed to de-assert video FIFO clear\n");
+		return ret;
 	}
 
-	if (!timeout) {
-		dev_err(dsi->dev, "Failed to enable Video clock\n");
-		return -ETIMEDOUT;
-	}
+	/* Enable transmission in video mode. */
+	rcar_mipi_dsi_set(dsi, TXVMCR, TXVMCR_EN_VIDEO);
 
-	/* Check Video transmission */
-	for (timeout = 10; timeout > 0; --timeout) {
-		status = rcar_mipi_dsi_read(dsi, TXVMSR);
-		if (status & TXVMSR_RDY)
-			break;
-
-		usleep_range(1000, 2000);
-	}
-
-	if (!timeout) {
-		dev_err(dsi->dev, "Failed to enable Video clock\n");
-		return -ETIMEDOUT;
+	ret = read_poll_timeout(rcar_mipi_dsi_read, status,
+				status & TXVMSR_RDY,
+				2000, 10000, false, dsi, TXVMSR);
+	if (ret < 0) {
+		dev_err(dsi->dev, "Failed to enable video transmission\n");
+		return ret;
 	}
 
-	dev_dbg(dsi->dev, "Start video transferring");
-
 	return 0;
 }
 
-- 
Regards,

Laurent Pinchart


  parent reply	other threads:[~2021-06-23  3:47 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-23  3:46 [RFC PATCH 00/15] R-Car V3U: DSI encoder driver Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 01/15] dt-bindings: display: bridge: Add binding for R-Car MIPI DSI/CSI-2 TX Laurent Pinchart
2021-06-23  9:06   ` Kieran Bingham
2021-06-23 13:06     ` Laurent Pinchart
2021-06-23 13:12     ` Geert Uytterhoeven
2021-06-23 14:36       ` Kieran Bingham
2021-06-23  3:46 ` [RFC PATCH 02/15] drm: rcar-du: Add R-Car DSI driver Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 03/15] drm: rcar-du: dsi: Use the correct compatible Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 04/15] drm: rcar-du: dsi: Reorganize probe function Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 05/15] drm: rcar-du: dsi: Use dev_err_probe() Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 06/15] drm: rcar-du: dsi: Shorten mipi_dsi variable name to dsi Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 07/15] drm: rcar-du: dsi: Use dsi->dev consistently in probe() Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 08/15] drm: rcar-du: dsi: Get next bridge " Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 09/15] drm: rcar-du: dsi: Simplify DT parsing Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 10/15] drm: rcar-du: dsi: Add error handling in rcar_mipi_dsi_clk_enable() Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 11/15] drm: rcar-du: dsi: Simplify error handling in rcar_mipi_dsi_enable() Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 12/15] drm: rcar-du: dsi: Turn container_of() wrappers to inline functions Laurent Pinchart
2021-06-23  3:46 ` [RFC PATCH 13/15] drm: rcar-du: dsi: Various style and typo fixes Laurent Pinchart
2021-06-23  3:46 ` Laurent Pinchart [this message]
2021-06-23  3:46 ` [RFC PATCH 15/15] drm: rcar-du: dsi: Include the DSI header Laurent Pinchart
2021-06-23 11:00 ` [RFC PATCH 16/15] rcar-du: dsi: Unexport clock functions Kieran Bingham
2021-06-23 13:11   ` Laurent Pinchart
2021-06-23 11:23 ` [RFC PATCH 00/15] R-Car V3U: DSI encoder driver Kieran Bingham

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=20210623034656.10316-15-laurent.pinchart+renesas@ideasonboard.com \
    --to=laurent.pinchart+renesas@ideasonboard.com \
    --cc=hoai.luu.ub@renesas.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=linux-renesas-soc@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.