media: ov5640: Fix power up sequence delays
v3 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.
Changes in v3:
- Move register-based reset to the common powerup_sequence function
- Only add 5ms delay for PWUP not for PWDN in ov5640_set_stream_dvp
v2: https://lore.kernel.org/all/[email protected]/
Jai Luthra (2):
media: ov5640: Handle delays when no reset_gpio set
media: ov5640: Fix soft reset sequence and timings
Nishanth Menon (1):
media: ov5640: Honor power on time in init_setting
drivers/media/i2c/ov5640.c | 68 +++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 20 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 1/3 media: ov5640: Handle delays when no reset_gpio set
Some module manufacturers [1][2] don't expose the RESETB and PWDN pins of the sensor directly through the 15-pin FFC connector. Instead wiring ~PWDN gpio to the sensor pins 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.
Also, rename the function to ov5640_powerup_sequence to better match the datasheet (section 2.7).
[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 | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
drivers/media/i2c/ov5640.c +16 -6
@@ -2424,11 +2424,22 @@ static void ov5640_power(struct ov5640_dev *sensor, bool enable)gpiod_set_value_cansleep (sensor->pwdn_gpio, enable ?0 :1 ); } -static void ov5640_reset (struct ov5640_dev *sensor) +/* +* From section 2.7 power up sequence: +* t0 + t1 + t2 >= 5ms Delay from DOVDD stable to PWDN pull down +* t3 >= 1ms Delay from PWDN pull down to RESETB pull up +* t4 >= 20ms Delay from RESETB pull up to SCCB (i2c) stable +* +* Some modules don't expose RESETB/PWDN pins directly, instead providing a +* "PWUP" GPIO which is wired through appropriate delays and inverters to the +* pins. +* +* In such cases, this gpio should be mapped to pwdn_gpio in the driver, and we +* should still toggle the pwdn_gpio below with the appropriate delays, while +* the calls to reset_gpio will be ignored. +*/ +static void ov5640_powerup_sequence (struct ov5640_dev *sensor) { -if (!sensor->reset_gpio) -return ; -gpiod_set_value_cansleep (sensor->reset_gpio,0 );/* camera power cycle */
@@ -2464,8 +2475,7 @@ static int ov5640_set_power_on(struct ov5640_dev *sensor) goto xclk_off; } -ov5640_reset (sensor); -ov5640_power (sensor, true); +ov5640_powerup_sequence (sensor); ret =ov5640_init_slave_id (sensor);if (ret)
Signature · 1 line
2.17.1
PATCH v3 2/3 media: ov5640: Fix soft reset sequence and timings
In reply to Jai LuthraMove the register-based reset out of the init_setting[] and into the powerup_sequence function. The sensor is power cycled and reset using the gpio pins so the soft reset is not always necessary.
This also ensures that soft reset honors the timing sequence from the datasheet [1].
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
--- drivers/media/i2c/ov5640.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)
drivers/media/i2c/ov5640.c +20 -10
@@ -50,6 +50,7 @@#define OV5640_REG_SYS_CTRL0 0x3008#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02 +#define OV5640_REG_SYS_CTRL0_SW_RST 0x82#define OV5640_REG_CHIP_ID 0x300a#define OV5640_REG_IO_MIPI_CTRL00 0x300e#define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017
@@ -532,7 +533,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 ,0x42 ,0 ,0 }, {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 },
@@ -2440,18 +2441,27 @@ static void ov5640_power(struct ov5640_dev *sensor, bool enable)*/ static void ov5640_powerup_sequence (struct ov5640_dev *sensor) { -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +if (sensor->pwdn_gpio) { +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); -/* camera power cycle */ -ov5640_power (sensor, false); -usleep_range (5000 ,10000 ); -ov5640_power (sensor, true); -usleep_range (5000 ,10000 ); +/* camera power cycle */ +ov5640_power (sensor, false); +usleep_range (5000 ,10000 ); +ov5640_power (sensor, true); +usleep_range (5000 ,10000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,1 ); -usleep_range (1000 ,2000 ); +gpiod_set_value_cansleep (sensor->reset_gpio,1 ); +usleep_range (1000 ,2000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); + }else { +/* software reset */ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_RST ); +usleep_range (5000 ,10000 ); +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP ); + }usleep_range (20000 ,25000 ); }
Signature · 1 line
2.17.1
Re: [PATCH v3 2/3] media: ov5640: Fix soft reset sequence and timings
Hi Jai
Quoted 29 lines · Jai Luthra
Move the register-based reset out of the init_setting[] and into the
powerup_sequencefunction. The sensor is power cycled and reset using the gpio pins so the soft reset is not always necessary.This also ensures that soft reset honors the timing sequence from the datasheet [1].
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Suggested-by Jacopo Mondi <[email protected]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)drivers/media/i2c/ov5640.c +1
-0@@ -50,6 +50,7 @@#define OV5640_REG_SYS_CTRL0 0x3008#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02 +#define OV5640_REG_SYS_CTRL0_SW_RST 0x82#define OV5640_REG_CHIP_ID 0x300a#define OV5640_REG_IO_MIPI_CTRL00 0x300e#define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017
drivers/media/i2c/ov5640.c static const struct v4l2_mbus_framefmt ov5640_default_fmt = { · line 536
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -532,7 +533,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 ,0x42 ,0 ,0 },
have you tried removing the second entry
{0x3008, 0x42, 0, 0},as well ?
The SW_PWDN state allows programming registers (how can you exit with SW_PWUP otherwise?), so it's probably right to have it there.
Quoted 26 lines
drivers/media/i2c/ov5640.c +9
-8{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},@@ -2440,18 +2441,27 @@ static void ov5640_power(struct ov5640_dev *sensor, bool enable)*/ static void ov5640_powerup_sequence (struct ov5640_dev *sensor) { -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +if (sensor->pwdn_gpio) { +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); -/* camera power cycle */ -ov5640_power (sensor, false); -usleep_range (5000 ,10000 ); -ov5640_power (sensor, true); -usleep_range (5000 ,10000 ); +/* camera power cycle */ +ov5640_power (sensor, false); +usleep_range (5000 ,10000 ); +ov5640_power (sensor, true); +usleep_range (5000 ,10000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,1 ); -usleep_range (1000 ,2000 ); +gpiod_set_value_cansleep (sensor->reset_gpio,1 ); +usleep_range (1000 ,2000 );
drivers/media/i2c/ov5640.c static void ov5640_power(struct ov5640_dev *sensor, bool enable) · line 2463
Quoted 10 lines
drivers/media/i2c/ov5640.c +8
-1-gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); + }else { +/* software reset */ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_RST ); +usleep_range (5000 ,10000 ); +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP );
But now I wonder if this last PWUP is necessary, since init_settings[] (which programs PWDN) is programmed immediately after.
Quoted 7 lines
drivers/media/i2c/ov5640.c +1
-1+ }usleep_range (20000 ,25000 ); } --2.17.1
Re: [PATCH v3 2/3] media: ov5640: Fix soft reset sequence and timings
Hi Jacopo,
Thank you for the comments.
Quoted 39 lines · Jacopo Mondi
Hi Jai
Quoted 29 lines · Jai Luthra
Move the register-based reset out of the init_setting[] and into the
powerup_sequencefunction. The sensor is power cycled and reset using the gpio pins so the soft reset is not always necessary.This also ensures that soft reset honors the timing sequence from the datasheet [1].
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Suggested-by Jacopo Mondi <[email protected]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)drivers/media/i2c/ov5640.c +1
-0@@ -50,6 +50,7 @@#define OV5640_REG_SYS_CTRL0 0x3008#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02 +#define OV5640_REG_SYS_CTRL0_SW_RST 0x82#define OV5640_REG_CHIP_ID 0x300a#define OV5640_REG_IO_MIPI_CTRL00 0x300e#define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017drivers/media/i2c/ov5640.c static const struct v4l2_mbus_framefmt ov5640_default_fmt = { · line 536
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -532,7 +533,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 ,0x42 ,0 ,0 },have you tried removing the second entry
Quoted 6 lines
{0x3008, 0x42, 0, 0},as well ?
The
SW_PWDNstate allows programming registers (how can you exit withSW_PWUPotherwise?), so it's probably right to have it there.
Yes, I initially removed it from here and kept it in the powerup_sequence() but logic to set SW_PWDN became in that function became a bit complicated:
When we are using HW pins, we want to wait 20ms after de-asserting RESET before doing any SCCB register writes. But when we are using SW reset, we were using this register write to de-assert RESET, and then wait 20ms.
I found it cleaner to just keep it here where the registers are being programmed for both the cases. But I don't have a strong opinion either way.
Quoted 30 lines
Quoted 30 lines
drivers/media/i2c/ov5640.c +9
-8{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},@@ -2440,18 +2441,27 @@ static void ov5640_power(struct ov5640_dev *sensor, bool enable)*/ static void ov5640_powerup_sequence (struct ov5640_dev *sensor) { -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +if (sensor->pwdn_gpio) { +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); -/* camera power cycle */ -ov5640_power (sensor, false); -usleep_range (5000 ,10000 ); -ov5640_power (sensor, true); -usleep_range (5000 ,10000 ); +/* camera power cycle */ +ov5640_power (sensor, false); +usleep_range (5000 ,10000 ); +ov5640_power (sensor, true); +usleep_range (5000 ,10000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,1 ); -usleep_range (1000 ,2000 ); +gpiod_set_value_cansleep (sensor->reset_gpio,1 ); +usleep_range (1000 ,2000 );
Quoted 12 lines
drivers/media/i2c/ov5640.c static void ov5640_power(struct ov5640_dev *sensor, bool enable) · line 2463
Quoted 9 lines
drivers/media/i2c/ov5640.c +8
-1-gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); + }else { +/* software reset */ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_RST ); +usleep_range (5000 ,10000 ); +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP );But now I wonder if this last PWUP is necessary, since init_settings[] (which programs PWDN) is programmed immediately after.
Using the PWUP (0x02) as a way to de-assert RST (0x42) here, and not as an actual PWUP per se.
Quoted 4 lines
drivers/media/i2c/ov5640.c static void ov5640_power(struct ov5640_dev *sensor, bool enable) · line 2465
Quoted 4 lines
drivers/media/i2c/ov5640.c +1
-0+ }usleep_range (20000 ,25000 );
Now that I think of it, we can move the PWDN from the register table to here, after this sleep - and keep the (0x02) above to de-assert reset. Let me know your thoughts.
Quoted 5 lines
Quoted 5 lines
drivers/media/i2c/ov5640.c +0
-1} --2.17.1
Thanks,
Jai
Re: [PATCH v3 2/3] media: ov5640: Fix soft reset sequence and timings
Hi Jay
Quoted 104 lines · Jai
Hi Jacopo,
Thank you for the comments.
Quoted 39 lines · Jacopo Mondi
Hi Jai
Quoted 29 lines · Jai Luthra
Move the register-based reset out of the init_setting[] and into the
powerup_sequencefunction. The sensor is power cycled and reset using the gpio pins so the soft reset is not always necessary.This also ensures that soft reset honors the timing sequence from the datasheet [1].
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Suggested-by Jacopo Mondi <[email protected]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)drivers/media/i2c/ov5640.c +1
-0@@ -50,6 +50,7 @@#define OV5640_REG_SYS_CTRL0 0x3008#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02 +#define OV5640_REG_SYS_CTRL0_SW_RST 0x82#define OV5640_REG_CHIP_ID 0x300a#define OV5640_REG_IO_MIPI_CTRL00 0x300e#define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017drivers/media/i2c/ov5640.c static const struct v4l2_mbus_framefmt ov5640_default_fmt = { · line 536
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -532,7 +533,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 ,0x42 ,0 ,0 },have you tried removing the second entry
Quoted 6 lines
{0x3008, 0x42, 0, 0},as well ?
The
SW_PWDNstate allows programming registers (how can you exit withSW_PWUPotherwise?), so it's probably right to have it there.Yes, I initially removed it from here and kept it in the
powerup_sequence()but logic to setSW_PWDNbecame in that function became a bit complicated:When we are using HW pins, we want to wait 20ms after de-asserting RESET before doing any SCCB register writes. But when we are using SW reset, we were using this register write to de-assert RESET, and then wait 20ms.
I found it cleaner to just keep it here where the registers are being programmed for both the cases. But I don't have a strong opinion either way.
Quoted 30 lines
Quoted 30 lines
drivers/media/i2c/ov5640.c +9
-8{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},@@ -2440,18 +2441,27 @@ static void ov5640_power(struct ov5640_dev *sensor, bool enable)*/ static void ov5640_powerup_sequence (struct ov5640_dev *sensor) { -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +if (sensor->pwdn_gpio) { +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); -/* camera power cycle */ -ov5640_power (sensor, false); -usleep_range (5000 ,10000 ); -ov5640_power (sensor, true); -usleep_range (5000 ,10000 ); +/* camera power cycle */ +ov5640_power (sensor, false); +usleep_range (5000 ,10000 ); +ov5640_power (sensor, true); +usleep_range (5000 ,10000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,1 ); -usleep_range (1000 ,2000 ); +gpiod_set_value_cansleep (sensor->reset_gpio,1 ); +usleep_range (1000 ,2000 );Quoted 12 lines
drivers/media/i2c/ov5640.c static void ov5640_power(struct ov5640_dev *sensor, bool enable) · line 2463
Quoted 9 lines
drivers/media/i2c/ov5640.c +8
-1-gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); + }else { +/* software reset */ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_RST ); +usleep_range (5000 ,10000 ); +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP );But now I wonder if this last PWUP is necessary, since init_settings[] (which programs PWDN) is programmed immediately after.
Quoted 1 line
Using the PWUP (
0x02) as a way to de-assert RST (0x42) here, and not as an
RST is 0x82 if I read it right
Quoted 2 lines
actual PWUP per se.
It is not necessary. The RST cleans up itself when the chip has done resetting. I tested it with:
@@ -2463,12 +2478,24 @@ static void ov5640_powerup_sequence(struct ov5640_dev *sensor)
gpiod_set_value_cansleep(sensor->reset_gpio, 0);
} else {
+ int ret;
+ u16 sysctrl = 0;
+ u16 counter = 0;
+
/* software reset */
ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0,
OV5640_REG_SYS_CTRL0_SW_RST);- usleep_range(5000, 10000);
- ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0,
- OV5640_REG_SYS_CTRL0_SW_PWUP);
+
+ do {
+ usleep_range(2000, 2500);
+ ret = ov5640_read_reg16(sensor, OV5640_REG_SYS_CTRL0,
+ &sysctrl);
+ if (ret)
+ pr_err("Failed to read sysctrl: %d\n", ret);
+ } while (sysctrl & BIT(7) || ++counter > 100);
+
+ pr_err("Exit from reset in %u loops\n", counter);
}
usleep_range(20000, 25000);The loop exists after 1 iteration
So I guess you can remove the last SW_PWUP write
Quoted 9 lines
Quoted 4 lines
drivers/media/i2c/ov5640.c static void ov5640_power(struct ov5640_dev *sensor, bool enable) · line 2465
Quoted 4 lines
drivers/media/i2c/ov5640.c +1
-0+ }usleep_range (20000 ,25000 );Now that I think of it, we can move the PWDN from the register table to here, after this sleep - and keep the (
0x02) above to de-assert reset. Let me know your thoughts.
Yes, I think it might be a good idea.
The diff on top of your series should be like
------------------------------------------------------------------------------
-- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -533,7 +533,7 @@ static const struct v4l2_mbus_framefmt ov5640_default_fmt = {
};
static const struct reg_value ov5640_init_setting[] = {
- {0x3103, 0x11, 0, 0}, {0x3008, 0x42, 0, 0},
+ {0x3103, 0x11, 0, 0},
{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},
@@ -2466,11 +2466,12 @@ static void ov5640_powerup_sequence(struct ov5640_dev *sensor)
/* software reset */
ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0,
OV5640_REG_SYS_CTRL0_SW_RST);
- usleep_range(5000, 10000);
- ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0,
- OV5640_REG_SYS_CTRL0_SW_PWUP);
}
usleep_range(20000, 25000);+
+ /* Software standby: allows registers programming; exit at s_stream(1) */
+ ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0,
+ OV5640_REG_SYS_CTRL0_SW_PWDN);
}
static int ov5640_set_power_on(struct ov5640_dev *sensor)
------------------------------------------------------------------------------
Do you agree with this ?
Also, since you have to resend, could you please swap the order of patches 1 and 2 ? It's more logically correct to plumb the SW reset handling in, then allow it to happen as you do in patch 1/3.
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
drivers/media/i2c/ov5640.c +0
-1} --2.17.1
Thanks,
Jai
Re: [PATCH v3 2/3] media: ov5640: Fix soft reset sequence and timings
Hi Jacopo,
Quoted 107 lines · Jacopo Mondi
Hi Jay
Quoted 104 lines · Jai
Hi Jacopo,
Thank you for the comments.
Quoted 39 lines · Jacopo Mondi
Hi Jai
Quoted 29 lines · Jai Luthra
Move the register-based reset out of the init_setting[] and into the
powerup_sequencefunction. The sensor is power cycled and reset using the gpio pins so the soft reset is not always necessary.This also ensures that soft reset honors the timing sequence from the datasheet [1].
[1] https://cdn.sparkfun.com/datasheets/Sensors/LightImaging/OV5640_datasheet.pdf
Fixes 19a81c1426c1 ("[media] add Omnivision OV5640 sensor driver")Suggested-by Jacopo Mondi <[email protected]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-)drivers/media/i2c/ov5640.c +1
-0@@ -50,6 +50,7 @@#define OV5640_REG_SYS_CTRL0 0x3008#define OV5640_REG_SYS_CTRL0_SW_PWDN 0x42#define OV5640_REG_SYS_CTRL0_SW_PWUP 0x02 +#define OV5640_REG_SYS_CTRL0_SW_RST 0x82#define OV5640_REG_CHIP_ID 0x300a#define OV5640_REG_IO_MIPI_CTRL00 0x300e#define OV5640_REG_PAD_OUTPUT_ENABLE01 0x3017drivers/media/i2c/ov5640.c static const struct v4l2_mbus_framefmt ov5640_default_fmt = { · line 536
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -532,7 +533,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 ,0x42 ,0 ,0 },have you tried removing the second entry
Quoted 6 lines
{0x3008, 0x42, 0, 0},as well ?
The
SW_PWDNstate allows programming registers (how can you exit withSW_PWUPotherwise?), so it's probably right to have it there.Yes, I initially removed it from here and kept it in the
powerup_sequence()but logic to setSW_PWDNbecame in that function became a bit complicated:When we are using HW pins, we want to wait 20ms after de-asserting RESET before doing any SCCB register writes. But when we are using SW reset, we were using this register write to de-assert RESET, and then wait 20ms.
I found it cleaner to just keep it here where the registers are being programmed for both the cases. But I don't have a strong opinion either way.
Quoted 42 lines
Quoted 29 lines
drivers/media/i2c/ov5640.c +9
-8{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},@@ -2440,18 +2441,27 @@ static void ov5640_power(struct ov5640_dev *sensor, bool enable)*/ static void ov5640_powerup_sequence (struct ov5640_dev *sensor) { -gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +if (sensor->pwdn_gpio) { +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); -/* camera power cycle */ -ov5640_power (sensor, false); -usleep_range (5000 ,10000 ); -ov5640_power (sensor, true); -usleep_range (5000 ,10000 ); +/* camera power cycle */ +ov5640_power (sensor, false); +usleep_range (5000 ,10000 ); +ov5640_power (sensor, true); +usleep_range (5000 ,10000 ); -gpiod_set_value_cansleep (sensor->reset_gpio,1 ); -usleep_range (1000 ,2000 ); +gpiod_set_value_cansleep (sensor->reset_gpio,1 ); +usleep_range (1000 ,2000 );drivers/media/i2c/ov5640.c static void ov5640_power(struct ov5640_dev *sensor, bool enable) · line 2463
Quoted 10 lines
drivers/media/i2c/ov5640.c +8
-1-gpiod_set_value_cansleep (sensor->reset_gpio,0 ); +gpiod_set_value_cansleep (sensor->reset_gpio,0 ); + }else { +/* software reset */ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_RST ); +usleep_range (5000 ,10000 ); +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP );But now I wonder if this last PWUP is necessary, since init_settings[] (which programs PWDN) is programmed immediately after.
Quoted 3 lines
Quoted 1 line
Using the PWUP (
0x02) as a way to de-assert RST (0x42) here, and not as anRST is
0x82if I read it right
Oops made a typo, yes RST is 0x82.
Quoted 36 lines
Quoted 3 lines
actual PWUP per se.
It is not necessary. The RST cleans up itself when the chip has done resetting. I tested it with:
(quoted diff) +14
-3@@ -2463,12 +2478,24 @@ static void ov5640_powerup_sequence(struct ov5640_dev *sensor) gpiod_set_value_cansleep(sensor->reset_gpio, 0); } else { + int ret; + u16 sysctrl = 0; + u16 counter = 0; + /* software reset */ ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, OV5640_REG_SYS_CTRL0_SW_RST); - usleep_range(5000, 10000); - ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, - OV5640_REG_SYS_CTRL0_SW_PWUP); + + do { + usleep_range(2000, 2500); + ret = ov5640_read_reg16(sensor, OV5640_REG_SYS_CTRL0, + &sysctrl); + if (ret) + pr_err("Failed to read sysctrl: %d\n", ret); + } while (sysctrl & BIT(7) || ++counter > 100); + + pr_err("Exit from reset in %u loops\n", counter); } usleep_range(20000, 25000);The loop exists after 1 iteration
Quoted 1 line
So I guess you can remove the last
SW_PWUPwrite
Great that simplifies things, thanks for that quick test!
Quoted 44 lines
Quoted 10 lines
Quoted 5 lines
drivers/media/i2c/ov5640.c static void ov5640_power(struct ov5640_dev *sensor, bool enable) · line 2465
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-0+ }usleep_range (20000 ,25000 );Now that I think of it, we can move the PWDN from the register table to here, after this sleep - and keep the (
0x02) above to de-assert reset. Let me know your thoughts.Yes, I think it might be a good idea.
The diff on top of your series should be like------------------------------------------------------------------------------
--a/drivers/media/i2c/ov5640.c
+++b/drivers/media/i2c/ov5640.cdrivers/media/i2c/ov5640.c +5
-5@@ -533,7 +533,7 @@ static const struct v4l2_mbus_framefmt ov5640_default_fmt = { };static const struct reg_value ov5640_init_setting[] = { - {0x3103 ,0x11 ,0 ,0 }, {0x3008 ,0x42 ,0 ,0 }, + {0x3103 ,0x11 ,0 ,0 }, {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 },@@ -2466,11 +2466,12 @@ static void ov5640_powerup_sequence(struct ov5640_dev *sensor)/* software reset */ ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 ,OV5640_REG_SYS_CTRL0_SW_RST ); -usleep_range (5000 ,10000 ); -ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , -OV5640_REG_SYS_CTRL0_SW_PWUP ); }usleep_range (20000 ,25000 ); + +/* Software standby: allows registers programming; exit at s_stream(1) */ +ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWDN ); }static int ov5640_set_power_on (struct ov5640_dev *sensor) ------------------------------------------------------------------------------
Quoted 5 lines
Do you agree with this ?
Also, since you have to resend, could you please swap the order of patches 1 and 2 ? It's more logically correct to plumb the SW reset handling in, then allow it to happen as you do in patch 1/3.
Makes sense, I will move the SW PWDN and re-order the patches in v4.
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
drivers/media/i2c/ov5640.c +0
-1} --2.17.1
Thanks,
Jai
Thanks,
Jai
PATCH v3 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 | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5640.c +12 -4
@@ -609,7 +609,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[] = {
@@ -1810,9 +1810,17 @@ static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on)static int ov5640_set_stream_dvp (struct ov5640_dev *sensor,bool on) { -return ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , on ? -OV5640_REG_SYS_CTRL0_SW_PWUP : -OV5640_REG_SYS_CTRL0_SW_PWDN ); +int ret; + +if (on) { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP ); +usleep_range (5000 ,6000 ); + }else { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWDN ); + } +return ret; }static int ov5640_set_stream_mipi (struct ov5640_dev *sensor,bool on)
Signature · 1 line
2.17.1
Re: [PATCH v3 3/3] media: ov5640: Honor power on time in init_setting
Hi Jai
Quoted 40 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]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/media/i2c/ov5640.c +2
-4@@ -609,7 +609,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[] = {@@ -1810,9 +1810,17 @@ static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on)static int ov5640_set_stream_dvp (struct ov5640_dev *sensor,bool on) { -return ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , on ? -OV5640_REG_SYS_CTRL0_SW_PWUP : -OV5640_REG_SYS_CTRL0_SW_PWDN ); +int ret;
drivers/media/i2c/ov5640.c static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on) · line 1823
Quoted 10 lines
drivers/media/i2c/ov5640.c +10
-0+ +if (on) { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP ); +usleep_range (5000 ,6000 ); + }else { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWDN ); + } +return ret;
Nipicking, I prefer maintaining the original version with just an additional usleep
int ret = ov5640_write_reg(sensor, OV5640_REG_SYS_CTRL0, on ?
OV5640_REG_SYS_CTRL0_SW_PWUP :
OV5640_REG_SYS_CTRL0_SW_PWDN);
if (on)
usleep_range(5000, 6000);
return ret;As you prefer
Quoted 6 lines
drivers/media/i2c/ov5640.c +0
-1}static int ov5640_set_stream_mipi (struct ov5640_dev *sensor,bool on) --2.17.1
Re: [PATCH v3 3/3] media: ov5640: Honor power on time in init_setting
In reply to Jai LuthraHi again
Quoted 24 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]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/media/i2c/ov5640.c +0
-0
drivers/media/i2c/ov5640.c static const struct reg_value ov5640_init_setting[] = { · line 612
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -609,7 +609,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},
This might also allow to remove the
/* remain in power down mode for DVP */ if (regs->reg_addr == OV5640_REG_SYS_CTRL0 && val == OV5640_REG_SYS_CTRL0_SW_PWUP && !ov5640_is_csi2(sensor)) continue;
in ov5640_load_regs()
Prabhakar since you have introduced it, coudl you test if you still need it with Nishanth's patch applied ?
Thanks
j
Quoted 27 lines
drivers/media/i2c/ov5640.c +11
-4};static const struct reg_value ov5640_setting_low_res[] = {@@ -1810,9 +1810,17 @@ static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on)static int ov5640_set_stream_dvp (struct ov5640_dev *sensor,bool on) { -return ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , on ? -OV5640_REG_SYS_CTRL0_SW_PWUP : -OV5640_REG_SYS_CTRL0_SW_PWDN ); +int ret; + +if (on) { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP ); +usleep_range (5000 ,6000 ); + }else { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWDN ); + } +return ret; }static int ov5640_set_stream_mipi (struct ov5640_dev *sensor,bool on) --2.17.1
Re: [PATCH v3 3/3] media: ov5640: Honor power on time in init_setting
Hello again
Quoted 41 lines · Jacopo Mondi
Hi again
Quoted 24 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]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/media/i2c/ov5640.c +0
-0drivers/media/i2c/ov5640.c static const struct reg_value ov5640_init_setting[] = { · line 612
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -609,7 +609,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},This might also allow to remove the
/* remain in power down mode for DVP */ if (regs->reg_addr == OV5640_REG_SYS_CTRL0 && val == OV5640_REG_SYS_CTRL0_SW_PWUP && !ov5640_is_csi2(sensor)) continue;
Quoted 4 lines
in
ov5640_load_regs()Prabhakar since you have introduced it, coudl you test if you still need it with Nishanth's patch applied ?
No, it doesn't, sorry for the confusion.
The following patch would allow to remove the above quirk by removing
{0x3008, 0x02}from the init_sequence[].
Unfortunately the first 3 images are then black when running in CSI-2 mode.
-------------------------------------------------------------------------------
drivers/media/i2c/ov5640.c +7 -5
@@ -609,7 +609,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, 5}, {0x3c00, 0x04, 0, 300}, + {0x3a1f, 0x14, 0, 0}, {0x3c00, 0x04, 0, 300}, }; static const struct reg_value ov5640_setting_low_res[] = {
@@ -1808,7 +1808,7 @@ static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on) BIT(1), on ? 0 : BIT(1)); } -static int ov5640_set_stream_dvp (struct ov5640_dev *sensor,bool on) +static int ov5640_set_stream (struct ov5640_dev *sensor,bool on) {int ret;
@@ -3725,11 +3725,13 @@ static int ov5640_s_stream(struct v4l2_subdev *sd, int enable) sensor->pending_fmt_change = false; } -if (ov5640_is_csi2 (sensor)) +if (ov5640_is_csi2 (sensor)) { ret =ov5640_set_stream_mipi (sensor, enable); -else - ret =ov5640_set_stream_dvp (sensor, enable); +if (ret) + goto out; + } + ret =ov5640_set_stream (sensor, enable);if (!ret) sensor->streaming = enable; }
-------------------------------------------------------------------------------
I do however now question the patch utility itself. SW PWDN is the software standby state, while Figure 2.3 and 2.4 you mention in the commit message report:
t2 = 5 ms: delay from DVDD stable to sensor power up stable
I doubt this apply to SW standby as it the delay is probably required to have the internal circuitry stabilize after the power rail has been enabled.
Does this patch make any practical difference in your setup ? I'm asking as in my case it doesn't, but I'm on a CSI-2 setup.
Quoted 32 lines
Thanks
jQuoted 27 lines
drivers/media/i2c/ov5640.c +11
-4};static const struct reg_value ov5640_setting_low_res[] = {@@ -1810,9 +1810,17 @@ static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on)static int ov5640_set_stream_dvp (struct ov5640_dev *sensor,bool on) { -return ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , on ? -OV5640_REG_SYS_CTRL0_SW_PWUP : -OV5640_REG_SYS_CTRL0_SW_PWDN ); +int ret; + +if (on) { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP ); +usleep_range (5000 ,6000 ); + }else { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWDN ); + } +return ret; }static int ov5640_set_stream_mipi (struct ov5640_dev *sensor,bool on) --2.17.1
Re: [PATCH v3 3/3] media: ov5640: Honor power on time in init_setting
Hi Jacopo,
Quoted 104 lines · Jacopo Mondi
Hello again
Quoted 41 lines · Jacopo Mondi
Hi again
Quoted 24 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]>Signed-off-by Jai Luthra <[email protected]>--- drivers/media/i2c/ov5640.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)drivers/media/i2c/ov5640.c +0
-0drivers/media/i2c/ov5640.c static const struct reg_value ov5640_init_setting[] = { · line 612
Quoted 5 lines
drivers/media/i2c/ov5640.c +1
-1@@ -609,7 +609,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},This might also allow to remove the
/* remain in power down mode for DVP */ if (regs->reg_addr == OV5640_REG_SYS_CTRL0 && val == OV5640_REG_SYS_CTRL0_SW_PWUP && !ov5640_is_csi2(sensor)) continue;Quoted 4 lines
in
ov5640_load_regs()Prabhakar since you have introduced it, coudl you test if you still need it with Nishanth's patch applied ?
No, it doesn't, sorry for the confusion.
The following patch would allow to remove the above quirk by removing
{0x3008, 0x02}from the init_sequence[].
Unfortunately the first 3 images are then black when running in CSI-2 mode.
-------------------------------------------------------------------------------
drivers/media/i2c/ov5640.c +7
-6@@ -609,7 +609,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, 5}, {0x3c00, 0x04, 0, 300}, + {0x3a1f, 0x14, 0, 0}, {0x3c00, 0x04, 0, 300}, }; static const struct reg_value ov5640_setting_low_res[] = {@@ -1808,7 +1808,7 @@ static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on) BIT(1), on ? 0 : BIT(1)); } -static int ov5640_set_stream_dvp (struct ov5640_dev *sensor,bool on) +static int ov5640_set_stream (struct ov5640_dev *sensor,bool on) {int ret;@@ -3725,11 +3725,13 @@ static int ov5640_s_stream(struct v4l2_subdev *sd, int enable) sensor->pending_fmt_change = false; } -if (ov5640_is_csi2 (sensor)) +if (ov5640_is_csi2 (sensor)) { ret =ov5640_set_stream_mipi (sensor, enable); -else - ret =ov5640_set_stream_dvp (sensor, enable); +if (ret) + goto out; + } + ret =ov5640_set_stream (sensor, enable);if (!ret) sensor->streaming = enable; } -------------------------------------------------------------------------------I do however now question the patch utility itself. SW PWDN is the software standby state, while Figure 2.3 and 2.4 you mention in the commit message report:
Quoted 5 lines
t2 = 5 ms: delay from DVDD stable to sensor power up stable
I doubt this apply to SW standby as it the delay is probably required to have the internal circuitry stabilize after the power rail has been enabled.
Good catch.
Quoted 3 lines
Does this patch make any practical difference in your setup ? I'm asking as in my case it doesn't, but I'm on a CSI-2 setup.
I tested today with this patch removed, and it does not make any difference to the probe success rate. We missed this during development as we first tried the SW powerdown and reset timing changes, and later the hardware reset timing changes [1/3].
I will drop this patch in the next series. Thanks for pointing this out.
Quoted 29 lines
Quoted 29 lines
Thanks
jQuoted 23 lines
drivers/media/i2c/ov5640.c +11
-3};static const struct reg_value ov5640_setting_low_res[] = {@@ -1810,9 +1810,17 @@ static int ov5640_set_autogain(struct ov5640_dev *sensor, bool on)static int ov5640_set_stream_dvp (struct ov5640_dev *sensor,bool on) { -return ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , on ? -OV5640_REG_SYS_CTRL0_SW_PWUP : -OV5640_REG_SYS_CTRL0_SW_PWDN ); +int ret; + +if (on) { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWUP ); +usleep_range (5000 ,6000 ); + }else { + ret =ov5640_write_reg (sensor,OV5640_REG_SYS_CTRL0 , +OV5640_REG_SYS_CTRL0_SW_PWDN ); + } +return ret; }
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/media/i2c/ov5640.c +0
-1static int ov5640_set_stream_mipi (struct ov5640_dev *sensor,bool on) --2.17.1
Thanks,
Jai