Skip to contentSkip to conversation

media: mt9p031: Increase post-reset delay

PATCH In review Marek Vasut 3 participants 4 messages Aug 23, 2022 – Nov 21, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 media: mt9p031: Increase post-reset delay

The MT9P006 sensor driver sporadically fails to probe because the sensor responds with a NACK condition to I2C address on the bus during an attempt to read the sensor MT9P031_CHIP_VERSION register in mt9p031_registered().

Neither the MT9P006 nor MT9P031 datasheets are clear on reset signal timing. Older MT9M034 [1] datasheet provides those timing figures in Appendix-A and indicates it is necessary to wait 850000 EXTCLK cycles before starting any I2C communication.

Add such a delay, which does make the sporadic I2C NACK go away, so it is likely similar constraint applies to this sensor.

[1] https://www.onsemi.com/pdf/datasheet/mt9m034-d.pdf

---
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Stefan Riedmueller <[email protected]>
---
V2: - In case clk_get_rate() returns 0, use slowest supported clock
to avoid division by zero

---
 drivers/media/i2c/mt9p031.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/i2c/mt9p031.c +7 -1
index 45f7b5e52bc39..5f5caafe56887 100644
@@ -307,6 +307,7 @@ static inline int mt9p031_pll_disable(struct mt9p031 *mt9p031)
 
 static int mt9p031_power_on(struct mt9p031 *mt9p031)
 {
+	unsigned long rate, delay;
 	int ret;
 
 	/* Ensure RESET_BAR is active */
@@ -334,7 +335,12 @@ static int mt9p031_power_on(struct mt9p031 *mt9p031)
 	/* Now RESET_BAR must be high */
 	if (mt9p031->reset) {
 		gpiod_set_value(mt9p031->reset, 0);
-		usleep_range(1000, 2000);
+		/* Wait 850000 EXTCLK cycles before de-asserting reset. */
+		rate = clk_get_rate(mt9p031->clk);
+		if (!rate)
+			rate = 6000000;	/* Slowest supported clock, 6 MHz */
+		delay = DIV_ROUND_UP(850000 * 1000, rate);
+		msleep(delay);
 	}
 
 	return 0;
Signature · 1 line
2.35.1
#1 lore raw
Quoted 15 lines · Marek Vasut

The MT9P006 sensor driver sporadically fails to probe because the sensor responds with a NACK condition to I2C address on the bus during an attempt to read the sensor MT9P031_CHIP_VERSION register in mt9p031_registered().

Neither the MT9P006 nor MT9P031 datasheets are clear on reset signal timing. Older MT9M034 [1] datasheet provides those timing figures in Appendix-A and indicates it is necessary to wait 850000 EXTCLK cycles before starting any I2C communication.

Add such a delay, which does make the sporadic I2C NACK go away, so it is likely similar constraint applies to this sensor.

[1] https://www.onsemi.com/pdf/datasheet/mt9m034-d.pdf

Quoted 8 lines

---
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Stefan Riedmueller <[email protected]>
---
V2: - In case clk_get_rate() returns 0, use slowest supported clock
to avoid division by zero

Any news on this patch ?

maintainer
#2 lore raw

Hi Marek,

Quoted 25 lines · Marek Vasut
Quoted 15 lines · Marek Vasut

The MT9P006 sensor driver sporadically fails to probe because the sensor responds with a NACK condition to I2C address on the bus during an attempt to read the sensor MT9P031_CHIP_VERSION register in mt9p031_registered().

Neither the MT9P006 nor MT9P031 datasheets are clear on reset signal timing. Older MT9M034 [1] datasheet provides those timing figures in Appendix-A and indicates it is necessary to wait 850000 EXTCLK cycles before starting any I2C communication.

Add such a delay, which does make the sporadic I2C NACK go away, so it is likely similar constraint applies to this sensor.

[1] https://www.onsemi.com/pdf/datasheet/mt9m034-d.pdf

Quoted 8 lines

---
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Stefan Riedmueller <[email protected]>
---
V2: - In case clk_get_rate() returns 0, use slowest supported clock
to avoid division by zero

Quoted 1 line

Any news on this patch ?

Thanks for the ping. It's in my tree now.

Signature · 3 lines
Kind regards,

Sakari Ailus
maintainer Reviewed-by on v2 1/1
#3 lore raw
In reply to Marek Vasut

Hi Marek,

Thank you for the patch.

Quoted 9 lines · Marek Vasut

The MT9P006 sensor driver sporadically fails to probe because the sensor responds with a NACK condition to I2C address on the bus during an attempt to read the sensor MT9P031_CHIP_VERSION register in mt9p031_registered().

Neither the MT9P006 nor MT9P031 datasheets are clear on reset signal timing. Older MT9M034 [1] datasheet provides those timing figures in Appendix-A and indicates it is necessary to wait 850000 EXTCLK cycles before starting any I2C communication.

Quoted 6 lines

Add such a delay, which does make the sporadic I2C NACK go away, so it is likely similar constraint applies to this sensor.

[1] https://www.onsemi.com/pdf/datasheet/mt9m034-d.pdf

Given the lack of information regarding the MT9P006 reset timings, this seems to be the best we can do.

Quoted 38 lines

---
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Sakari Ailus <[email protected]>
Cc: Stefan Riedmueller <[email protected]>
---
V2: - In case clk_get_rate() returns 0, use slowest supported clock
to avoid division by zero

---
 drivers/media/i2c/mt9p031.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/i2c/mt9p031.c +7 -1
index 45f7b5e52bc39..5f5caafe56887 100644
@@ -307,6 +307,7 @@ static inline int mt9p031_pll_disable(struct mt9p031 *mt9p031)
 
 static int mt9p031_power_on(struct mt9p031 *mt9p031)
 {
+	unsigned long rate, delay;
 	int ret;
 
 	/* Ensure RESET_BAR is active */
@@ -334,7 +335,12 @@ static int mt9p031_power_on(struct mt9p031 *mt9p031)
 	/* Now RESET_BAR must be high */
 	if (mt9p031->reset) {
 		gpiod_set_value(mt9p031->reset, 0);
-		usleep_range(1000, 2000);
+		/* Wait 850000 EXTCLK cycles before de-asserting reset. */
+		rate = clk_get_rate(mt9p031->clk);
+		if (!rate)
+			rate = 6000000;	/* Slowest supported clock, 6 MHz */
+		delay = DIV_ROUND_UP(850000 * 1000, rate);
+		msleep(delay);
 	}
 
 	return 0;
Signature · 3 lines
Regards,

Laurent Pinchart