diff mbox series

[v3,1/2] media: max9271: Ignore busy loop read errors

Message ID 20211108133833.57059-1-jacopo+renesas@jmondi.org (mailing list archive)
State New, archived
Headers show
Series max9271: Fix pclk detect silent failure | expand

Commit Message

Jacopo Mondi Nov. 8, 2021, 1:38 p.m. UTC
Valid pixel clock detection is performed by spinning on a register read,
which if repeated too frequently might fail. As the error is not fatal
ignore it instead of bailing out to continue spinning until the timeout
completion.

Also relax the time between bus transactions and slightly increase the
wait interval to mitigate the failure risk.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

---

v2->v3:
- Remove goto as suggested by Geert

v1->v2:
- Do not continue but jump to a label to respect the sleep timout after a
  failed read

Niklas I kept your tag anyway, hope it's ok.
---
 drivers/media/i2c/max9271.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

--
2.33.1
diff mbox series

Patch

diff --git a/drivers/media/i2c/max9271.c b/drivers/media/i2c/max9271.c
index ff86c8c4ea61..f0dbc7337101 100644
--- a/drivers/media/i2c/max9271.c
+++ b/drivers/media/i2c/max9271.c
@@ -55,7 +55,7 @@  static int max9271_write(struct max9271_device *dev, u8 reg, u8 val)
 /*
  * max9271_pclk_detect() - Detect valid pixel clock from image sensor
  *
- * Wait up to 10ms for a valid pixel clock.
+ * Wait up to 15ms for a valid pixel clock.
  *
  * Returns 0 for success, < 0 for pixel clock not properly detected
  */
@@ -64,15 +64,12 @@  static int max9271_pclk_detect(struct max9271_device *dev)
 	unsigned int i;
 	int ret;

-	for (i = 0; i < 100; i++) {
+	for (i = 0; i < 10; i++) {
 		ret = max9271_read(dev, 0x15);
-		if (ret < 0)
-			return ret;
-
-		if (ret & MAX9271_PCLKDET)
+		if (ret > 0 && (ret & MAX9271_PCLKDET))
 			return 0;

-		usleep_range(50, 100);
+		usleep_range(1000, 1500);
 	}

 	dev_err(&dev->client->dev, "Unable to detect valid pixel clock\n");