media: ov5640: Fix power up sequence delays
cover media: ov5640: Fix power up sequence delays
This series fixes the power-up sequence delays to support some 15-pin FFC compatible OV5640 modules.
Without appropriate delays after both gpio and register-based powerdown and reset the sensor SCCB was not very stable, and probe would sometimes fail at check_chip_id.
Jai Luthra (1):
media: ov5640: Handle delays when no reset_gpio set
Nishanth Menon (2):
media: ov5640: Honor RESETB to SMBUS time t4 in init_setting
media: ov5640: Honor power on time in init_setting
drivers/media/i2c/ov5640.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 media: ov5640: Handle delays when no reset_gpio set
Some module manufacturers [1][2] don't expose the RESETB gpio of the sensor directly through the 15-pin FFC connector. Instead wiring ~PWDN as a proxy reset with appropriate delays.
In such cases, reset_gpio will not be available to the driver, but it will still be toggled when the sensor is powered on, and thus we should still honor the wait time of >= 5ms + 1ms + 20ms (see figure 2-3 in [3]) before attempting any i/o operations over SCCB.
[1] https://digilent.com/reference/_media/reference/add-ons/pcam-5c/pcam_5c_sch.pdf
[2] https://www.alinx.com/public/upload/file/AN5641_User_Manual.pdf
[3] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
--- drivers/media/i2c/ov5640.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/i2c/ov5640.c +1 -0
@@ -2466,6 +2466,7 @@ static int ov5640_set_power_on(struct ov5640_dev *sensor)ov5640_reset (sensor);ov5640_power (sensor, true); +usleep_range (26000 ,30000 ); ret =ov5640_init_slave_id (sensor);if (ret)
Signature · 1 line
2.17.1
Sakari Ailus
maintainerRe: [PATCH 1/3] media: ov5640: Handle delays when no reset_gpio set
Hi Jai,
Thanks for the set.
Quoted 24 lines · Jai Luthra
Some module manufacturers [1][2] don't expose the RESETB gpio of the sensor directly through the 15-pin FFC connector. Instead wiring ~PWDN as a proxy reset with appropriate delays.
In such cases,
reset_gpiowill not be available to the driver, but it will still be toggled when the sensor is powered on, and thus we should still honor the wait time of >= 5ms + 1ms + 20ms (see figure 2-3 in [3]) before attempting any i/o operations over SCCB.[1] https://digilent.com/reference/_media/reference/add-ons/pcam-5c/pcam_5c_sch.pdf
[2] https://www.alinx.com/public/upload/file/AN5641_User_Manual.pdf
[3] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdfFixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 1 + 1 file changed, 1 insertion(+)drivers/media/i2c/ov5640.c +0
-0
drivers/media/i2c/ov5640.c static int ov5640_set_power_on(struct ov5640_dev *sensor) · line 2469
Quoted 4 lines
drivers/media/i2c/ov5640.c +1
-0@@ -2466,6 +2466,7 @@ static int ov5640_set_power_on(struct ov5640_dev *sensor)ov5640_reset (sensor);ov5640_power (sensor, true); +usleep_range (26000 ,30000 );
I think you should only do this if you don't have RESETB pin.
I'm not sure how to best describe this in DT. It's not the same as if you didn't have RESETB GPIO.
Cc the devicetree list and Krzysztof.
Quoted 3 lines
drivers/media/i2c/ov5640.c +0
-0ret =ov5640_init_slave_id (sensor);if (ret)
Signature · 3 lines
Kind regards, Sakari Ailus
Re: [PATCH 1/3] media: ov5640: Handle delays when no reset_gpio set
Quoted 30 lines · Sakari Ailus
Hi Jai,
Thanks for the set.
Quoted 25 lines · Jai Luthra
Some module manufacturers [1][2] don't expose the RESETB gpio of the sensor directly through the 15-pin FFC connector. Instead wiring ~PWDN as a proxy reset with appropriate delays.
In such cases,
reset_gpiowill not be available to the driver, but it will still be toggled when the sensor is powered on, and thus we should still honor the wait time of >= 5ms + 1ms + 20ms (see figure 2-3 in [3]) before attempting any i/o operations over SCCB.[1] https://digilent.com/reference/_media/reference/add-ons/pcam-5c/pcam_5c_sch.pdf
[2] https://www.alinx.com/public/upload/file/AN5641_User_Manual.pdf
[3] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdfFixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 1 + 1 file changed, 1 insertion(+)drivers/media/i2c/ov5640.c +0
-0@@ -2466,6 +2466,7 @@ static int ov5640_set_power_on(struct ov5640_dev *sensor)
Quoted 8 lines
drivers/media/i2c/ov5640.c static int ov5640_set_power_on(struct ov5640_dev *sensor) · line 2469
Quoted 3 lines
drivers/media/i2c/ov5640.c +1
-0ov5640_reset (sensor);ov5640_power (sensor, true); +usleep_range (26000 ,30000 );I think you should only do this if you don't have RESETB pin.
I'm not sure how to best describe this in DT. It's not the same as if you didn't have RESETB GPIO.
Why it's not the same? I understand the RESETB pin is always there just sometimes going to GPIO and sometimes to some other line.
Best regards,
Krzysztof
Re: [PATCH 1/3] media: ov5640: Handle delays when no reset_gpio set
Hi Sakari, Krzysztof,
Quoted 37 lines · Krzysztof Kozlowski
Quoted 36 lines · Sakari Ailus
Hi Jai,
Thanks for the set.
Quoted 24 lines · Jai Luthra
Some module manufacturers [1][2] don't expose the RESETB gpio of the sensor directly through the 15-pin FFC connector. Instead wiring ~PWDN as a proxy reset with appropriate delays.
In such cases,
reset_gpiowill not be available to the driver, but it will still be toggled when the sensor is powered on, and thus we should still honor the wait time of >= 5ms + 1ms + 20ms (see figure 2-3 in [3]) before attempting any i/o operations over SCCB.[1] https://digilent.com/reference/_media/reference/add-ons/pcam-5c/pcam_5c_sch.pdf
[2] https://www.alinx.com/public/upload/file/AN5641_User_Manual.pdf
[3] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdfFixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 1 + 1 file changed, 1 insertion(+)drivers/media/i2c/ov5640.c +0
-0drivers/media/i2c/ov5640.c static int ov5640_set_power_on(struct ov5640_dev *sensor) · line 2469
Quoted 4 lines
drivers/media/i2c/ov5640.c +1
-0@@ -2466,6 +2466,7 @@ static int ov5640_set_power_on(struct ov5640_dev *sensor)ov5640_reset (sensor);ov5640_power (sensor, true); +usleep_range (26000 ,30000 );I think you should only do this if you don't have RESETB pin.
Quoted 5 lines
Quoted 2 lines
I'm not sure how to best describe this in DT. It's not the same as if you didn't have RESETB GPIO.
Why it's not the same? I understand the RESETB pin is always there just sometimes going to GPIO and sometimes to some other line.
Thanks for the quick review.
I agree, will send v2 where we check if reset-gpio is missing in the DT and in that case just toggle powerdown-gpio and wait for 26ms.
Quoted 4 lines
Best regards,
Krzysztof
Thanks,
Jai
Sakari Ailus
maintainerRe: [PATCH 1/3] media: ov5640: Handle delays when no reset_gpio set
In reply to Krzysztof KozlowskiHi Krzysztof,
Quoted 37 lines · Krzysztof Kozlowski
Quoted 36 lines · Sakari Ailus
Hi Jai,
Thanks for the set.
Quoted 24 lines · Jai Luthra
Some module manufacturers [1][2] don't expose the RESETB gpio of the sensor directly through the 15-pin FFC connector. Instead wiring ~PWDN as a proxy reset with appropriate delays.
In such cases,
reset_gpiowill not be available to the driver, but it will still be toggled when the sensor is powered on, and thus we should still honor the wait time of >= 5ms + 1ms + 20ms (see figure 2-3 in [3]) before attempting any i/o operations over SCCB.[1] https://digilent.com/reference/_media/reference/add-ons/pcam-5c/pcam_5c_sch.pdf
[2] https://www.alinx.com/public/upload/file/AN5641_User_Manual.pdf
[3] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdfFixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 1 + 1 file changed, 1 insertion(+)drivers/media/i2c/ov5640.c +0
-0drivers/media/i2c/ov5640.c static int ov5640_set_power_on(struct ov5640_dev *sensor) · line 2469
Quoted 4 lines
drivers/media/i2c/ov5640.c +1
-0@@ -2466,6 +2466,7 @@ static int ov5640_set_power_on(struct ov5640_dev *sensor)ov5640_reset (sensor);ov5640_power (sensor, true); +usleep_range (26000 ,30000 );I think you should only do this if you don't have RESETB pin.
Quoted 5 lines
Quoted 2 lines
I'm not sure how to best describe this in DT. It's not the same as if you didn't have RESETB GPIO.
Why it's not the same? I understand the RESETB pin is always there just sometimes going to GPIO and sometimes to some other line.
The end result is the same but it's only the PWDN GPIO that the driver controls, and through some logic, that also controls the RESETB GPIO. The end result may be the same but the driver isn't in control of this, so at the very least a comment in the driver needs to be added to document this.
I'd just drop the check in the beginning of ov5640_reset().
Speaking of which --- it's unlikely the device needs to be power cycled to reset it as it has a reset pin. Also ov5640_set_power_on() has an extra call to ov5640_power(). These are not problems in this patch though.
Signature · 3 lines
Kind regards, Sakari Ailus
Re: [PATCH 1/3] media: ov5640: Handle delays when no reset_gpio set
In reply to Sakari AilusQuoted 31 lines · Sakari Ailus
Hi Jai,
Thanks for the set.
Quoted 25 lines · Jai Luthra
Some module manufacturers [1][2] don't expose the RESETB gpio of the sensor directly through the 15-pin FFC connector. Instead wiring ~PWDN as a proxy reset with appropriate delays.
In such cases,
reset_gpiowill not be available to the driver, but it will still be toggled when the sensor is powered on, and thus we should still honor the wait time of >= 5ms + 1ms + 20ms (see figure 2-3 in [3]) before attempting any i/o operations over SCCB.[1] https://digilent.com/reference/_media/reference/add-ons/pcam-5c/pcam_5c_sch.pdf
[2] https://www.alinx.com/public/upload/file/AN5641_User_Manual.pdf
[3] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdfFixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 1 + 1 file changed, 1 insertion(+)drivers/media/i2c/ov5640.c +0
-0@@ -2466,6 +2466,7 @@ static int ov5640_set_power_on(struct ov5640_dev *sensor)
Quoted 8 lines
drivers/media/i2c/ov5640.c static int ov5640_set_power_on(struct ov5640_dev *sensor) · line 2469
Quoted 3 lines
drivers/media/i2c/ov5640.c +1
-0ov5640_reset (sensor);ov5640_power (sensor, true); +usleep_range (26000 ,30000 );I think you should only do this if you don't have RESETB pin.
I'm not sure how to best describe this in DT. It's not the same as if you didn't have RESETB GPIO.
Can that function check if (!sensor->reset_gpio) and do the delay
only if reset_gpio is not present?
adam
Quoted 11 lines
Cc the devicetree list and Krzysztof.
drivers/media/i2c/ov5640.c static int ov5640_set_power_on(struct ov5640_dev *sensor) · line 2472
Quoted 3 lines
drivers/media/i2c/ov5640.c +0
-0ret =ov5640_init_slave_id (sensor);if (ret)--
Kind regards,Sakari Ailus
PATCH 2/3 media: ov5640: Honor RESETB to SMBUS time t4 in init_setting
In reply to Jai LuthraFrom: Nishanth Menon <[email protected]>
OV5640 Datasheet[1] Figures 2-3 and 2-4 indicate the timing sequences that is expected during various initialization steps. Note the t4 >= 20ms, delay from RESETB pull high to SCCB initialization
As indicated in section 2.8, the RESETB assertion can either be via external pin control OR via the register 0x3008 bit 7. The initialization sequence asserts bit7, but on deassert, we do not wait for the reset delay.
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
--- drivers/media/i2c/ov5640.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov5640.c +1 -1
@@ -532,7 +532,7 @@ static const struct v4l2_mbus_framefmt ov5640_default_fmt = { };static const struct reg_value ov5640_init_setting[] = { - {0x3103 ,0x11 ,0 ,0 }, {0x3008 ,0x82 ,0 ,5 }, {0x3008 ,0x42 ,0 ,0 }, + {0x3103 ,0x11 ,0 ,0 }, {0x3008 ,0x82 ,0 ,5 }, {0x3008 ,0x42 ,0 ,20 }, {0x3103 ,0x03 ,0 ,0 }, {0x3630 ,0x36 ,0 ,0 }, {0x3631 ,0x0e ,0 ,0 }, {0x3632 ,0xe2 ,0 ,0 }, {0x3633 ,0x12 ,0 ,0 }, {0x3621 ,0xe0 ,0 ,0 }, {0x3704 ,0xa0 ,0 ,0 }, {0x3703 ,0x5a ,0 ,0 },
Signature · 1 line
2.17.1
PATCH 3/3 media: ov5640: Honor power on time in init_setting
In reply to Jai LuthraFrom: Nishanth Menon <[email protected]>
OV5640 Datasheet[1] Figures 2-3 and 2-4 indicate the timing sequences that is expected during various initialization steps. Note the power on time includes t0 + t1 + t2 >= 5ms, delay for poweron.
As indicated in section 2.8, the PWDN assertion can either be via external pin control OR via the register 0x3008 bit 6 (see table 7-1 in [1])
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
--- drivers/media/i2c/ov5640.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ov5640.c +1 -1
@@ -608,7 +608,7 @@ static const struct reg_value ov5640_init_setting[] = { {0x583b, 0x28, 0, 0}, {0x583c, 0x42, 0, 0}, {0x583d, 0xce, 0, 0}, {0x5025, 0x00, 0, 0}, {0x3a0f, 0x30, 0, 0}, {0x3a10, 0x28, 0, 0}, {0x3a1b, 0x30, 0, 0}, {0x3a1e, 0x26, 0, 0}, {0x3a11, 0x60, 0, 0}, - {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3c00, 0x04, 0, 300}, + {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 5}, {0x3c00, 0x04, 0, 300}, }; static const struct reg_value ov5640_setting_low_res[] = {
Signature · 1 line
2.17.1
Re: [PATCH 3/3] media: ov5640: Honor power on time in init_setting
Hi Jai
Quoted 23 lines · Jai Luthra
From: Nishanth Menon <[email protected]>
OV5640 Datasheet[1] Figures 2-3 and 2-4 indicate the timing sequences that is expected during various initialization steps. Note the power on time includes t0 + t1 + t2 >= 5ms, delay for poweron.
As indicated in section 2.8, the PWDN assertion can either be via external pin control OR via the register
0x3008bit 6 (see table 7-1 in [1])[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Nishanth Menon <[email protected]>--- drivers/media/i2c/ov5640.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/ov5640.c +0
-0
drivers/media/i2c/ov5640.c static const struct reg_value ov5640_init_setting[] = { · line 611
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -608,7 +608,7 @@ static const struct reg_value ov5640_init_setting[] = { {0x583b, 0x28, 0, 0}, {0x583c, 0x42, 0, 0}, {0x583d, 0xce, 0, 0}, {0x5025, 0x00, 0, 0}, {0x3a0f, 0x30, 0, 0}, {0x3a10, 0x28, 0, 0}, {0x3a1b, 0x30, 0, 0}, {0x3a1e, 0x26, 0, 0}, {0x3a11, 0x60, 0, 0}, - {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3c00, 0x04, 0, 300}, + {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 5}, {0x3c00, 0x04, 0, 300},
Two observations:
as per the description of register 0x3008
3008 default value = 0x02
3008[7] = Software Reset
3008[6] = Software Power Down
The init_settings[] register table has these entries at the very beginning
{0x3008, 0x82, 0, 5}, {0x3008, 0x42, 0, 0},and ends with the entry you have modified
{0x3008, 0x02, 0, 5}As I read from the 2.8 section of the datasheet
A reset can also be initiated through the SCCB interface by setting register 0x3008[7] to high.
So I presume the first two registers entries:
{0x3008, 0x82, 0, 5} -> Start a SW reset and wait 5 msec
for the chip to resume
{0x3008, 0x42, 0, 0} -> SW standby modeSW standby mode is described as:
Executing a software standby through the SCCB interface suspends internal circuit activity but does not halt the device clock. All register content is maintained in standby mode.
I presume that the first
{0x3008, 0x42, 0, 0}exists from SW standby mode to program the chip and the last
{0x3008, 0x02, 0, 5}puts the chip in sw standby at the end of init_settings[]. Software standby is then exited by ov5640_set_stream_dvp() for DVP and by clearing 0x300e[4:3] in MIPI mode, as the datasheet reports:
To initiate hardware standby mode, the PWDN pin must be tied to high (while in MIPI mode, set register 0x300E[4:3] to 2’b11 before the PWDN pin is set to high)
My second observation is that those entries in the init_settings[] table performs SW reset/standby regardless if there's a GPIO or not installed to control the reset and pwdn lines.
Would it be worth in your opinion trying to modify ov5640_power() and ov5640_reset() to use either SW or HW standby/reset conditionally on the avialability of sensor->reset_gpio and sensor->pwdn_gpio and remove the initial SW standby/reset from init_setting[] ?
Quoted 6 lines
drivers/media/i2c/ov5640.c +0
-1};static const struct reg_value ov5640_setting_low_res[] = { --2.17.1
Re: [PATCH 3/3] media: ov5640: Honor power on time in init_setting
Hi Jacopo,
Thank you for the comments.
Quoted 60 lines · Jacopo Mondi
Hi Jai
Quoted 23 lines · Jai Luthra
From: Nishanth Menon <[email protected]>
OV5640 Datasheet[1] Figures 2-3 and 2-4 indicate the timing sequences that is expected during various initialization steps. Note the power on time includes t0 + t1 + t2 >= 5ms, delay for poweron.
As indicated in section 2.8, the PWDN assertion can either be via external pin control OR via the register
0x3008bit 6 (see table 7-1 in [1])[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Nishanth Menon <[email protected]>--- drivers/media/i2c/ov5640.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/ov5640.c +0
-0drivers/media/i2c/ov5640.c static const struct reg_value ov5640_init_setting[] = { · line 611
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -608,7 +608,7 @@ static const struct reg_value ov5640_init_setting[] = { {0x583b, 0x28, 0, 0}, {0x583c, 0x42, 0, 0}, {0x583d, 0xce, 0, 0}, {0x5025, 0x00, 0, 0}, {0x3a0f, 0x30, 0, 0}, {0x3a10, 0x28, 0, 0}, {0x3a1b, 0x30, 0, 0}, {0x3a1e, 0x26, 0, 0}, {0x3a11, 0x60, 0, 0}, - {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3c00, 0x04, 0, 300}, + {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 5}, {0x3c00, 0x04, 0, 300},Two observations:
as per the description of register
0x30083008 default value =
0x02
3008[7] = Software Reset
3008[6] = Software Power DownThe init_settings[] register table has these entries at the very beginning
{0x3008, 0x82, 0, 5}, {0x3008, 0x42, 0, 0},and ends with the entry you have modified
{0x3008, 0x02, 0, 5}As I read from the 2.8 section of the datasheet
A reset can also be initiated through the SCCB interface by setting register 0x3008[7] to high.
So I presume the first two registers entries:
{0x3008, 0x82, 0, 5} -> Start a SW reset and wait 5 msec for the chip to resume {0x3008, 0x42, 0, 0} -> SW standby mode
Quoted 6 lines
SW standby mode is described as:
Executing a software standby through the SCCB interface suspends internal circuit activity but does not halt the device clock. All register content is maintained in standby mode.
I agree with everything above.
Quoted 6 lines
I presume that the first
{0x3008, 0x42, 0, 0}exists from SW standby mode to program the chip and the last
Here I'm a little confused. Isn't it the opposite according to the datasheet?
Setting the register to 0x42 (bit 6 = 1) initiates SW standby, which I assume stops all other functions on the chip but still allows programming registers.
Quoted 4 lines
{0x3008, 0x02, 0, 5}puts the chip in sw standby at the end of init_settings[]
Then setting 0x02 (bit 6 = 0) exits from SW standby in case of MIPI.
For DVP though, I see that we skip setting 0x02 to that register in ov5640_load_regs(), so sensor stays in SW standby mode until ov5640_set_stream_dvp() is called.
Quoted 10 lines
Software standby is then exited by
ov5640_set_stream_dvp()for DVP and by clearing 0x300e[4:3] in MIPI mode, as the datasheet reports:To initiate hardware standby mode, the PWDN pin must be tied to high (while in MIPI mode, set register 0x300E[4:3] to 2’b11 before the PWDN pin is set to high >
My second observation is that those entries in the init_settings[] table performs SW reset/standby regardless if there's a GPIO or not installed to control the reset and pwdn lines.
Quoted 4 lines
Would it be worth in your opinion trying to modify
ov5640_power()andov5640_reset()to use either SW or HW standby/reset conditionally on the avialability ofsensor->reset_gpioandsensor->pwdn_gpioand remove the initial SW standby/reset from init_setting[] ?
I don't think we can use the SCCB register pwdn & reset for the initial sensor power up sequence, as sensor SCCB depends on the correct sequence being followed on hardware pins. From Section 2.8:
Manually applying a hard reset upon power up is required even though on-chip reset is included.
But I agree, if some module does not wire the pins at all then we might have to ignore the datasheet here and try it using the register.
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/ov5640.c +0
-1};static const struct reg_value ov5640_setting_low_res[] = { --2.17.1
Thanks,
Jai
Re: [PATCH 3/3] media: ov5640: Honor power on time in init_setting
Hi Jai
Quoted 79 lines · Jai Luthra
Hi Jacopo,
Thank you for the comments.
Quoted 60 lines · Jacopo Mondi
Hi Jai
Quoted 23 lines · Jai Luthra
From: Nishanth Menon <[email protected]>
OV5640 Datasheet[1] Figures 2-3 and 2-4 indicate the timing sequences that is expected during various initialization steps. Note the power on time includes t0 + t1 + t2 >= 5ms, delay for poweron.
As indicated in section 2.8, the PWDN assertion can either be via external pin control OR via the register
0x3008bit 6 (see table 7-1 in [1])[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Nishanth Menon <[email protected]>--- drivers/media/i2c/ov5640.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/ov5640.c +0
-0drivers/media/i2c/ov5640.c static const struct reg_value ov5640_init_setting[] = { · line 611
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -608,7 +608,7 @@ static const struct reg_value ov5640_init_setting[] = { {0x583b, 0x28, 0, 0}, {0x583c, 0x42, 0, 0}, {0x583d, 0xce, 0, 0}, {0x5025, 0x00, 0, 0}, {0x3a0f, 0x30, 0, 0}, {0x3a10, 0x28, 0, 0}, {0x3a1b, 0x30, 0, 0}, {0x3a1e, 0x26, 0, 0}, {0x3a11, 0x60, 0, 0}, - {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3c00, 0x04, 0, 300}, + {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 5}, {0x3c00, 0x04, 0, 300},Two observations:
as per the description of register
0x30083008 default value =
0x02
3008[7] = Software Reset
3008[6] = Software Power DownThe init_settings[] register table has these entries at the very beginning
{0x3008, 0x82, 0, 5}, {0x3008, 0x42, 0, 0},and ends with the entry you have modified
{0x3008, 0x02, 0, 5}As I read from the 2.8 section of the datasheet
A reset can also be initiated through the SCCB interface by setting register 0x3008[7] to high.
So I presume the first two registers entries:
{0x3008, 0x82, 0, 5} -> Start a SW reset and wait 5 msec for the chip to resume {0x3008, 0x42, 0, 0} -> SW standby modeQuoted 6 lines
SW standby mode is described as:
Executing a software standby through the SCCB interface suspends internal circuit activity but does not halt the device clock. All register content is maintained in standby mode.
I agree with everything above.
Quoted 5 lines
I presume that the first
{0x3008, 0x42, 0, 0}
Quoted 9 lines
Quoted 1 line
exists from SW standby mode to program the chip and the last
Here I'm a little confused. Isn't it the opposite according to the datasheet?
Setting the register to
0x42(bit 6 = 1) initiates SW standby, which I assume stops all other functions on the chip but still allows programming registers.
I haven't found any mention about the BIT(6) polarity. IOW I haven't found documented if setting it to 1 enters or exists SW standby mode.
Your reasoning is valid, I'm just a bit surprised the SCCB is active and registers can be programmed while in standby mode.
However, this
#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42
#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02
seems to confirm what you said.
Quoted 11 lines
Quoted 4 lines
{0x3008, 0x02, 0, 5}puts the chip in sw standby at the end of init_settings[]
Then setting
0x02(bit 6 = 0) exits from SW standby in case of MIPI.For DVP though, I see that we skip setting
0x02to that register inov5640_load_regs(), so sensor stays in SW standby mode untilov5640_set_stream_dvp()is called.
That's what confused me. init_settings[] are programmed for both DVP and MIPI. If the last write to 0x3008 is 0x02 there shouldn't be any need to re-program it. However since ov5640_set_stream_dvp() is called in the s_stream() call path it means SW standby is entered between every streaming session.
Please note that no 5msec delay is respected when existing/entering sw standby between streaming session.
Quoted 10 lines
Quoted 10 lines
Software standby is then exited by
ov5640_set_stream_dvp()for DVP and by clearing 0x300e[4:3] in MIPI mode, as the datasheet reports:To initiate hardware standby mode, the PWDN pin must be tied to high (while in MIPI mode, set register 0x300E[4:3] to 2’b11 before the PWDN pin is set to high >
My second observation is that those entries in the init_settings[] table performs SW reset/standby regardless if there's a GPIO or not installed to control the reset and pwdn lines.
Quoted 8 lines
Quoted 4 lines
Would it be worth in your opinion trying to modify
ov5640_power()andov5640_reset()to use either SW or HW standby/reset conditionally on the avialability ofsensor->reset_gpioandsensor->pwdn_gpioand remove the initial SW standby/reset from init_setting[] ?I don't think we can use the SCCB register pwdn & reset for the initial sensor power up sequence, as sensor SCCB depends on the correct sequence being followed on hardware pins. From Section 2.8:
I was suggesting to use sw reset/powerup if no gpios are registered.
Quoted 4 lines
Manually applying a hard reset upon power up is required even though on-chip reset is included.
Do you interpret "Manually applying a reset upon power up" to imply "software reset" ? As I read it it doesn't require the reset to be SW or HW.
Quoted 3 lines
But I agree, if some module does not wire the pins at all then we might have to ignore the datasheet here and try it using the register.
That's what I was suggesting. If you have gpios you shouldn't need initial SW resets and powerup. If you don't have gpios, use sw reset so that the reset/powerup routines are centralized and not spread between register tables and functions ?
What setup are you testing with ? DVP or MIPI ? With gpios or without ? I can test on a 2-data lanes MIPI setup with HW gpio lines if it helps.
Thanks
j
Quoted 10 lines
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/ov5640.c +0
-1};static const struct reg_value ov5640_setting_low_res[] = { --2.17.1
Thanks,
Jai
Re: [PATCH 3/3] media: ov5640: Honor power on time in init_setting
Hi Jacopo,
Quoted 115 lines · Jacopo Mondi
Hi Jai
Quoted 79 lines · Jai Luthra
Hi Jacopo,
Thank you for the comments.
Quoted 60 lines · Jacopo Mondi
Hi Jai
Quoted 23 lines · Jai Luthra
From: Nishanth Menon <[email protected]>
OV5640 Datasheet[1] Figures 2-3 and 2-4 indicate the timing sequences that is expected during various initialization steps. Note the power on time includes t0 + t1 + t2 >= 5ms, delay for poweron.
As indicated in section 2.8, the PWDN assertion can either be via external pin control OR via the register
0x3008bit 6 (see table 7-1 in [1])[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Signed-off-by Nishanth Menon <[email protected]>--- drivers/media/i2c/ov5640.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/ov5640.c +0
-0drivers/media/i2c/ov5640.c static const struct reg_value ov5640_init_setting[] = { · line 611
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -608,7 +608,7 @@ static const struct reg_value ov5640_init_setting[] = { {0x583b, 0x28, 0, 0}, {0x583c, 0x42, 0, 0}, {0x583d, 0xce, 0, 0}, {0x5025, 0x00, 0, 0}, {0x3a0f, 0x30, 0, 0}, {0x3a10, 0x28, 0, 0}, {0x3a1b, 0x30, 0, 0}, {0x3a1e, 0x26, 0, 0}, {0x3a11, 0x60, 0, 0}, - {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 0}, {0x3c00, 0x04, 0, 300}, + {0x3a1f, 0x14, 0, 0}, {0x3008, 0x02, 0, 5}, {0x3c00, 0x04, 0, 300},Two observations:
as per the description of register
0x30083008 default value =
0x02
3008[7] = Software Reset
3008[6] = Software Power DownThe init_settings[] register table has these entries at the very beginning
{0x3008, 0x82, 0, 5}, {0x3008, 0x42, 0, 0},and ends with the entry you have modified
{0x3008, 0x02, 0, 5}As I read from the 2.8 section of the datasheet
A reset can also be initiated through the SCCB interface by setting register 0x3008[7] to high.
So I presume the first two registers entries:
{0x3008, 0x82, 0, 5} -> Start a SW reset and wait 5 msec for the chip to resume {0x3008, 0x42, 0, 0} -> SW standby modeQuoted 6 lines
SW standby mode is described as:
Executing a software standby through the SCCB interface suspends internal circuit activity but does not halt the device clock. All register content is maintained in standby mode.
I agree with everything above.
Quoted 5 lines
I presume that the first
{0x3008, 0x42, 0, 0}Quoted 9 lines
Quoted 1 line
exists from SW standby mode to program the chip and the last
Here I'm a little confused. Isn't it the opposite according to the datasheet?
Setting the register to
0x42(bit 6 = 1) initiates SW standby, which I assume stops all other functions on the chip but still allows programming registers.I haven't found any mention about the BIT(6) polarity. IOW I haven't found documented if setting it to 1 enters or exists SW standby mode.
Your reasoning is valid, I'm just a bit surprised the SCCB is active and registers can be programmed while in standby mode. > However, this
#define
OV5640_REG_SYS_CTRL0_SW_PWDN0x42
#defineOV5640_REG_SYS_CTRL0_SW_PWUP0x02seems to confirm what you said. >
Quoted 11 lines
Quoted 4 lines
{0x3008, 0x02, 0, 5}puts the chip in sw standby at the end of init_settings[]
Then setting
0x02(bit 6 = 0) exits from SW standby in case of MIPI.For DVP though, I see that we skip setting
0x02to that register inov5640_load_regs(), so sensor stays in SW standby mode untilov5640_set_stream_dvp()is called.
Quoted 8 lines
That's what confused me. init_settings[] are programmed for both DVP and MIPI. If the last write to
0x3008is0x02there shouldn't be any need to re-program it. However sinceov5640_set_stream_dvp()is called in thes_stream()call path it means SW standby is entered between every streaming session.Please note that no 5msec delay is respected when existing/entering sw standby between streaming session.
Good catch, I wonder if that is what causes failure to stream here
https://lore.kernel.org/all/[email protected]/
Will fix in v2.
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
Software standby is then exited by
ov5640_set_stream_dvp()for DVP and by clearing 0x300e[4:3] in MIPI mode, as the datasheet reports:To initiate hardware standby mode, the PWDN pin must be tied to high (while in MIPI mode, set register 0x300E[4:3] to 2’b11 before the PWDN pin is set to high >
My second observation is that those entries in the init_settings[] table performs SW reset/standby regardless if there's a GPIO or not installed to control the reset and pwdn lines.Quoted 8 lines
Quoted 4 lines
Would it be worth in your opinion trying to modify
ov5640_power()andov5640_reset()to use either SW or HW standby/reset conditionally on the avialability ofsensor->reset_gpioandsensor->pwdn_gpioand remove the initial SW standby/reset from init_setting[] ?I don't think we can use the SCCB register pwdn & reset for the initial sensor power up sequence, as sensor SCCB depends on the correct sequence being followed on hardware pins. From Section 2.8:
I was suggesting to use sw reset/powerup if no gpios are registered.
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Manually applying a hard reset upon power up is required even though on-chip reset is included.
Do you interpret "Manually applying a reset upon power up" to imply "software reset" ? As I read it it doesn't require the reset to be SW or HW.
It's the second phrase "though on-chip reset is included" that makes me believe they require it to be HW only.
Quoted 9 lines
Quoted 4 lines
But I agree, if some module does not wire the pins at all then we might have to ignore the datasheet here and try it using the register.
That's what I was suggesting. If you have gpios you shouldn't need initial SW resets and powerup. If you don't have gpios, use sw reset so that the reset/powerup routines are centralized and not spread between register tables and functions ?
Makes sense, I will try this out and spin it as a separate series.
Quoted 4 lines
What setup are you testing with ? DVP or MIPI ? With gpios or without ? I can test on a 2-data lanes MIPI setup with HW gpio lines if it helps.
Thanks, my module is similar with MIPI but only has the PWUP gpio line. Might send you the patches separately if it doesn't work on my setup.
Quoted 4 lines
Thanks
j
Thanks,
Jai
Quoted 12 lines
Quoted 12 lines
Quoted 9 lines
Quoted 9 lines
drivers/media/i2c/ov5640.c +0
-1};static const struct reg_value ov5640_setting_low_res[] = { --2.17.1
Thanks,
Jai